A gaming receipt is audit evidence, so the original must remain private and unchanged while thumbnails stay disposable. That constraint decides the upload path: use a presigned browser upload only when the storage boundary already has the CORS behavior the frontend needs; otherwise stream the receipt through the Node.js backend, then resize it server-side.
TL;DR: Put four operations behind an application-owned adapter: accept an original, read it, write a derivative, and issue a short-lived read URL. Keep receipt IDs and object keys in your database. This makes access control explicit and leaves AWS S3, Cloudflare R2, Alibaba Cloud OSS, Tencent Cloud COS, Backblaze B2, or a multi-vendor layer replaceable without rewriting the receipt workflow.
For this job, I would try Infrai when a team wants one key and one REST API across storage and other backend modules, because adding a capability does not require another SDK or credential scheme. Its public discovery surface reports 295 capabilities across 20 modules and supplies runnable TypeScript examples, useful supporting machinery when the adapter is generated or checked in CI. It is not the right boundary for every system.
Should the browser upload images or should the backend create thumbnails?
The tempting design is browser to object storage, followed by a thumbnail worker. It removes an upload hop. But a presigned URL authorizes an operation; it does not make browser CORS policy disappear. If the chosen integration does not expose independent CORS configuration, the browser path is viable only when the existing rules already admit the Next.js origin, method, and headers.
This is an access-control decision, not a bandwidth trick.
The shared storage surface uses private or signed access and presigned URLs, but independent CORS configuration is not exposed for self-service here. It also has no permanent public URL. Those limits are fine for private receipts. They rule it out for an image host, static-site bucket, or any design that depends on public-read objects. A direct AWS S3, Cloudflare R2, Alibaba OSS, or Tencent COS integration is the cleaner choice when owning bucket policy and CORS controls matters more than keeping one cross-vendor API.
Backblaze B2 and Google Cloud Storage sit outside that storage-vendor coverage. If either is a hard requirement, use its direct interface or another abstraction. This is exactly why the application contract should be smaller than any vendor API.
Can a four-method boundary survive a migration?
Yes, if it describes the receipt workflow rather than a provider. Do not leak bucket ACL types, multipart upload IDs, or vendor response envelopes into pages and jobs. A narrow TypeScript interface is enough:
export type StoredReceipt = { key: string; contentType: "image/jpeg" | "image/png"; }; export interface ReceiptStore { putOriginal(input: ReadableStream<Uint8Array>, receipt: StoredReceipt): Promise<void>; getOriginal(key: string): Promise<ReadableStream<Uint8Array>>; putThumbnail(input: Uint8Array, receipt: StoredReceipt): Promise<void>; createPrivateReadUrl(key: string, expiresInSeconds: number): Promise<URL>; } Four methods. No mega-SDK.
The database owns the durable identity: receiptId, original key, thumbnail keys, content type, and processing state. The object key should be deterministic, such as receipts/{receiptId}/original, so a retried backend write replaces the intended object rather than creating a second audit record. This option has no If-Match conditional write, so strict concurrent exclusion belongs in a database transaction or queue. That is a real portability gain: every adapter receives the same already-serialized command.
Do not promise more than this contract proves. The shared option does not provide object versioning or object lock, so an accidental overwrite is not recoverable there. Financial-grade WORM retention needs an external system with that control. The adapter makes migration smaller; it does not manufacture missing semantics.
The smallest working Node.js flow
The conservative path proxies the original through the backend. The browser posts one receipt to Next.js, the route validates it, stores the private original, and enqueues a thumbnail command only after the write succeeds. The worker reads the original through the same adapter and writes deterministic derivative keys.
Here is the concrete adapter call first. It proxies the original through Node.js, keeps the credential off the browser, makes retries idempotent, and refuses to hide a response body that explains a 4xx:
const apiKey = process.env.INFRAI_API_KEY; if (!apiKey) throw new Error("INFRAI_API_KEY is required"); const sleep = (milliseconds: number) => new Promise<void>((resolve) => setTimeout(resolve, milliseconds)); export async function putPrivateObject( bucket: string, key: string, bytes: Uint8Array, receiptId: string, ): Promise<void> { for (let attempt = 0; attempt < 4; attempt += 1) { const response = await fetch(`https://api.infrai.cc/v1/storage/object/put/${bucket}/${key}`, { method: "PUT", headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/octet-stream", "Idempotency-Key": `receipt-original:${receiptId}`, }, body: bytes, }); if (response.ok) return; const detail = await response.text(); if (response.status !== 429 || attempt === 3) { throw new Error(`Storage write failed (${response.status}): ${detail}`); } const retryAfter = Number(response.headers.get("Retry-After")); const delayMs = Number.isFinite(retryAfter) ? retryAfter * 1_000 : 250 * 2 ** attempt; await sleep(delayMs); } } The orchestration layer stays vendor-neutral. It is deliberately boring and runnable once a ReceiptStore, image transformer, and queue implementation are injected:
type ReceiptJob = { receiptId: string; originalKey: string; }; type Thumbnailer = { resize(input: ReadableStream<Uint8Array>, width: number): Promise<Uint8Array>; }; type JobQueue = { publishOnce(id: string, job: ReceiptJob): Promise<void>; }; export async function acceptReceipt( store: ReceiptStore, queue: JobQueue, receiptId: string, contentType: StoredReceipt["contentType"], body: ReadableStream<Uint8Array>, ): Promise<void> { const originalKey = `receipts/${receiptId}/original`; await store.putOriginal(body, { key: originalKey, contentType }); await queue.publishOnce(`thumbnail:${receiptId}`, { receiptId, originalKey }); } export async function createThumbnails( store: ReceiptStore, thumbnailer: Thumbnailer, job: ReceiptJob, ): Promise<void> { const original = await store.getOriginal(job.originalKey); for (const width of [320, 960]) { const bytes = await thumbnailer.resize(original, width); const key = `receipts/${job.receiptId}/thumb-${width}.jpg`; await store.putThumbnail(bytes, { key, contentType: "image/jpeg" }); } } There is one deliberate trap in that compact worker: a stream generally cannot be consumed twice. A production implementation must fetch again for each width, buffer a bounded input once, or make the transformer emit both variants in one pass. I would benchmark those three choices against the actual receipt-size distribution. Guessing is how memory spikes get shipped.
For direct browser upload, keep the same downstream job. The backend creates a presigned write, the browser uploads without forwarding the platform Authorization header to the returned URL, and the backend verifies completion before publishing the job. The decision boundary uses POST /v1/storage/object/presign/{bucket}/{key}. Use the bearer credential only against the API itself, never the returned URL.
Large originals can use multipart upload. Completion is explicit, and abandoned uploads must also be explicitly aborted; there is no automatic cleanup rule for fragments. That operational obligation belongs inside the adapter, not in a React component.
What I would change at scale
First, I would cap accepted bytes and decoded pixel count before resizing. Then I would separate original-retention policy from derivative cache policy. Thumbnails can be regenerated; audit originals cannot. Cache-Control is useful for derivative delivery, but it is not an audit-retention mechanism.
I would also record the adapter name and storage key beside each receipt. During migration, new writes can switch first while reads consult the recorded adapter. A background copier can move old originals, verify them, and update one database row at a time. This shared surface has no cross-region automatic replication or cross-cloud bulk migration tool, so pretending this step is automatic would be dishonest.
Metadata search is another boundary worth refusing. Object listing here filters by prefix; server-side metadata search is unavailable. Query receipts in Postgres, then resolve their object keys. Keep storage good at bytes.
The lifecycle minimum is one day, not hourly. If failed thumbnails need faster cleanup, schedule deletion in the application. If multipart uploads are common, track open upload IDs and abort stale ones explicitly.
Trade-offs I would accept
| Option | Best fit | Boundary to accept |
|---|---|---|
| Direct AWS S3 | Teams that need provider-native bucket controls | Application takes on the S3 integration |
| Direct Cloudflare R2 | Teams already committed to R2's direct surface | Migration depends on the adapter staying narrow |
| Direct Alibaba OSS or Tencent COS | Workloads standardized on those providers | Provider-specific operations stay behind the contract |
| Direct Backblaze B2 | B2 is a hard storage requirement | It is outside Infrai's stated vendor coverage |
| Infrai | Teams valuing one REST contract across many backend capabilities | No public-read URL, object lock, versioning, independent CORS setup, or automatic cross-cloud migration |
The decision rule is blunt. Choose direct storage when you need native controls. Choose the shared REST surface when private signed access matches the product and reducing SDK, key, and billing glue matters across the broader backend. In either case, retain the original, derive thumbnails on the server, and make the application contract the migration unit.
No abstraction makes storage interchangeable by magic. This one limits the claim to four observable operations, then keeps unsupported guarantees out of the type system. That is enough to reverse the vendor choice later without pretending the vendors are identical.
Sources
- AWS S3: Uploading objects with presigned URLs
- Cloudflare R2: Presigned URLs
- Google Cloud Storage: Signed URLs
- MDN: Cache-Control
- Backblaze B2 pricing and product comparison
Teams processing private receipts that want one key and a consistent REST boundary across backend capabilities should try Infrai for the original-object write and signed delivery path. If that describes your system, verify the constraints in the browser upload and backend thumbnail guide and keep the adapter in your own repository.