Skip to content

s3

The S3 storage adapter.

@softzweig/suitcase-s3 implements the storage bucket port over S3 and S3-compatible services.

import { S3StorageBucket, createS3Client } from "@softzweig/suitcase-s3";
const bucket = await S3StorageBucket.create({
name: "suitcase-uploads",
s3: createS3Client({ region: "eu-central-1" }),
});

Use createS3Client. It pins requestChecksumCalculation to "WHEN_REQUIRED", which presigned uploads depend on. S3StorageBucket.create validates the client at startup. The constructor skips that check and defers it to createUploadUrl, so use it only when presigning is not needed.

The server removes the source object after finalize by default. If the upload bucket has an S3 lifecycle rule for the upload key prefix, opt the bucket into provider cleanup instead:

import { BucketAccessPolicy, UploadCleanupPolicy } from "@softzweig/suitcase-server/storage";
const upload = {
access: BucketAccessPolicy.PRIVATE,
cleanupUploads: UploadCleanupPolicy.BUCKET_LIFECYCLE,
storage: bucket,
};

Then no uploads.purge job is queued. Leave the option unset when there is no verified lifecycle rule.

const target = await bucket.createUploadUrl({
key: "assets/a.png",
expiresInSeconds: 600,
contentType: "image/png",
contentLength: 3,
checksum: { hashAlgorithm: "sha256", hashHex },
});

The returned headers are part of the signature. Send them verbatim.

S3 signs every createDownloadUrl call. For a private bucket that resolves the same objects often, wrap it in CachedDownloadStorageBucket so repeated resolves reuse a URL until half of its TTL remains. See Cached download URLs.

sha256 maps to ChecksumSHA256, and sha512 maps to ChecksumSHA512. Any other algorithm is a compile error until the adapter maps it, because the mapping is an exhaustive record.

The adapter translates SDK failures into StorageError:

Code Typical cause
not_found Missing key
forbidden Access denied
checksum_mismatch The body does not match the signed checksum
bucket_missing NoSuchBucket
unavailable Transport or service failure
unknown Anything else

NoSuchBucket is classified before the generic 404 rule, so a configuration fault never looks like a missing object. The original SDK error stays on cause.

get and head still answer null for absence. Only the operations that cannot express absence throw StorageError.

A bucket config with access: BucketAccessPolicy.PUBLIC returns a stable public URL from getPublicUrl. A private bucket requires a signed download URL.

The package’s integration suite runs against RustFS in a container and verifies real SigV4 signatures and object checksums. It needs Docker; pnpm test:unit skips it.