Storage adapters
The bucket port, the S3 adapter, and what a custom adapter must guarantee.
A bucket is a configured storage adapter plus an access policy. The server never talks to a provider directly, so the same definition can run on S3, in memory, or on a backend you write.
The port
Section titled “The port”A StorageBucket is created for one bucket name and exposes:
putandgetfor server-side objects;createUploadUrlandcreateDownloadUrlfor presigned requests;headandlistfor metadata and pagination;removeandcopyfor lifecycle work;getPublicUrlfor a public bucket.
The bucket name is not passed per call. The adapter instance owns it.
Missing objects answer null from get and head, not an error. Failures use a small vocabulary:
not_found, forbidden, checksum_mismatch, bucket_missing, unavailable, unknown. Adapters
translate their provider’s errors into that vocabulary, and the original error stays reachable
through cause.
import { S3StorageBucket, createS3Client } from "@softzweig/suitcase-s3";
const bucket = await S3StorageBucket.create({ name: "suitcase-uploads", s3: createS3Client({ region: "eu-central-1" }),});Presigned uploads
Section titled “Presigned uploads”const { url, method, headers } = await bucket.createUploadUrl({ key: "assets/a.png", expiresInSeconds: 600, contentType: "image/png", contentLength: 3, checksum: { hashAlgorithm: "sha256", hashHex },});
await fetch(url, { method, headers, body });Every returned header is part of the signature. Headers you do not pass in are never signed, so the URL carries no obligation the client cannot fulfil.
Checksums
Section titled “Checksums”The core contract allows sha256 and sha512. The S3 adapter maps them to ChecksumSHA256 and
ChecksumSHA512 and rejects anything else at compile time when a new algorithm is added without a
mapping.
Access policy
Section titled “Access policy”import { BucketAccessPolicy } from "@softzweig/suitcase-server/storage";
const config = { access: BucketAccessPolicy.PRIVATE, storage: bucket,};PUBLIC lets reads use getPublicUrl and skips signing. PRIVATE keeps reads behind a signed URL.
The policy belongs to the config, not to a kind, so put public content in its own bucket.
Upload cleanup
Section titled “Upload cleanup”The upload bucket also chooses who removes the source object after finalize has copied it into the
kind’s bucket. The default is UploadCleanupPolicy.DELETE_AFTER_FINALIZE, which queues
uploads.purge:
import { BucketAccessPolicy, UploadCleanupPolicy, type UploadBucketConfig,} from "@softzweig/suitcase-server/storage";
const upload: UploadBucketConfig = { access: BucketAccessPolicy.PRIVATE, cleanupUploads: UploadCleanupPolicy.BUCKET_LIFECYCLE, // opt out of the purge job storage: uploadBucket,};Omit cleanupUploads, or set it to UploadCleanupPolicy.DELETE_AFTER_FINALIZE, to have the server
queue uploads.purge after finalize. Set UploadCleanupPolicy.BUCKET_LIFECYCLE only when the bucket
has a verified lifecycle rule that expires the upload key prefix. The server then skips the purge job
and leaves cleanup to the provider. Lifecycle expiry is asynchronous and provider-specific, so
DELETE_AFTER_FINALIZE remains the safer default.
Caching downloads
Section titled “Caching downloads”Private S3 reads can reuse signed URLs instead of signing one per resolve. See Cached download URLs for the wrapper, edge caching, and cost tradeoffs.
The memory bucket
Section titled “The memory bucket”createMemoryBucketConfig is for development and tests. It is a real bucket implementation in one
process: nothing is durable, other instances cannot see its objects, and memory is the only limit.
It is useful for a local server or a test that needs real storage behavior without infrastructure.
Writing an adapter
Section titled “Writing an adapter”Keep the provider’s specifics inside the package. An adapter should:
- own its bucket name and never ask callers for it;
- translate provider errors into
StorageErrorand keep the cause; - return
nullfor absence rather than throwing; - echo exactly the headers a presigned request needs;
- treat
checksumas an obligation when the provider supports it; - return an opaque cursor from
list, not a provider-specific token.
The service layer authorizes and validates. The adapter stores bytes and reports what the provider did.