Short answer: treat the original receipt as an audit record first, then choose multipart upload as the transport. Keep upload state in your database, keep the object immutable after completion, and make completion and abort explicit transitions.

I run a one-person SaaS, so I measure infrastructure in revenue per hour. The useful question isn't “can this upload finish?” It's “can I explain exactly what happened to this receipt six months later?” Ship weekly. Outsource the undifferentiated transfer work, but keep the evidence boundary visible in code.

Start with the evidence, not the upload call

An AI-generated image, scanner capture, or phone photo can all become a receipt original. The bytes need one stable object key tied to a tenant and receipt identifier. The database record should also hold who started the upload, the expected byte count, a content-type allowlist decision, and a retention deadline. A client filename is display data, not identity.

This ordering changes the implementation. Create a server-owned session before handing out any presigned URL. Store the upload ID and expiry before the client sends a part. If the process crashes, a worker can still find the session and decide whether to resume, complete, or abort it. There is no mystery “maybe the request committed” state hidden inside a web handler.

The original object gets a write-once policy in the application, even when the storage service technically permits replacement. A review image can be derived later under a different key. That separation makes an audit export deterministic: original bytes, digest, and event history travel together.

How can a Node.js multipart upload preserve a large generated image for audit?

The following adapter names are deliberately generic. A concrete S3-compatible client supplies the multipart primitives; the application owns authorization, persistence, and the state machine around them.

type Part = { number: number; etag: string }; type UploadSession = { id: string; objectKey: string; expiresAt: number }; interface StorageAdapter { createMultipart(key: string, contentType: string): Promise<{ uploadId: string }>; presignPart(key: string, uploadId: string, partNumber: number, ttlSeconds: number): Promise<string>; completeMultipart(key: string, uploadId: string, parts: Part[]): Promise<{ etag: string }>; abortMultipart(key: string, uploadId: string): Promise<void>; head(key: string): Promise<{ size: number; sha256?: string }>; } export async function beginReceiptUpload( storage: StorageAdapter, receiptId: string, sizeBytes: number, contentType: string, ): Promise<{ session: UploadSession; urls: string[] }> { if (!contentType.startsWith("image/") || sizeBytes <= 0) { throw new Error("invalid receipt payload"); } const objectKey = `receipts/${receiptId}/original`; const { uploadId } = await storage.createMultipart(objectKey, contentType); const partSize = 16 * 1024 * 1024; const count = Math.ceil(sizeBytes / partSize); const urls = await Promise.all( Array.from({ length: count }, (_, index) => storage.presignPart(objectKey, uploadId, index + 1, 900), ), ); const session = { id: uploadId, objectKey, expiresAt: Date.now() + 15 * 60_000 }; // Persist the session and tenant ownership before returning URLs. return { session, urls }; } export async function finishReceiptUpload( storage: StorageAdapter, session: UploadSession, parts: Part[], expectedSize: number, ): Promise<void> { if (Date.now() > session.expiresAt) throw new Error("upload session expired"); if (parts.length === 0 || parts.some((part) => !part.etag)) { throw new Error("parts missing"); } await storage.completeMultipart(session.objectKey, session.id, parts); const object = await storage.head(session.objectKey); if (object.size !== expectedSize) throw new Error("size verification failed"); // Mark the receipt immutable only after head() confirms the final object. } export async function abortReceiptUpload( storage: StorageAdapter, session: UploadSession, ): Promise<void> { await storage.abortMultipart(session.objectKey, session.id); // The expiry worker may retry this transition before closing the session row. } 

The 16 MiB part size is an example policy, not a protocol requirement. The important invariants are narrower: URLs are scoped to one part and expire after 900 seconds, the completion list comes from the client but is validated against the session, and head checks the physical size before the business row becomes immutable. Presigned URLs are bearer credentials, so never put them in logs. In a real receipt flow I also keep the generator job ID, tenant ID, and digest in the same record; that lets an auditor start with a claim, follow one database row to one object key, and see every transition without searching application logs for a transient URL or guessing which retry won. That extra join is cheap compared with reconstructing provenance after a support ticket, especially when several workers have attempted the same image.

An ETag is useful for completing a multipart request, but it is not a universal file digest. Multipart semantics can make it describe a composition. Compute and store SHA-256 separately when the audit policy needs byte-level evidence. I learned that distinction the hard way in a prototype; the fix was one explicit digest field, not a cleverer ETag parser.

Which state transitions make cleanup and delivery explainable?

Keep a small ledger with states such as open, completed, aborting, aborted, and expired. Record an event before each remote call, including an attempt number and the object key, then record the observed result. A worker can claim expired rows with a lease, re-check the deadline, call abort, and converge on aborted on a later pass if the process stops between the two writes.

That ledger also gives support a useful answer. “The customer saw a spinner” is not an audit event; “part 4 was presigned at 14:03 UTC, completion was accepted at 14:11, and the final object measured 48,217,901 bytes” is. Keep tenant authorization checks on begin, complete, and abort. The key namespace is an extra guard, never the authorization system.

At scale, separate metrics for started, completed, aborted, and expired sessions. Alert on the oldest open session and the expired-session ratio. Total object count misses leaked parts. Encryption, restricted reads, and documented retention controls still matter; FedRAMP's control catalog is a useful reference for the surrounding evidence, even though it does not prescribe one upload API.

When is multipart the wrong delivery boundary?

Multipart adds browser state, CORS configuration, clock-skew sensitivity, and recovery UI. It is not suitable when images are tiny, retention is disposable, or nobody can operate the expiry worker. A single authenticated upload endpoint can be the responsible choice when its simpler failure surface is more valuable than resumability.

The catch is ownership. Direct-to-storage transfer saves application bandwidth, but it moves part retries and user feedback into code you now own. My rule is to adopt multipart when restarting a transfer or losing its evidence costs more than maintaining that state machine. Your mileage may vary; network quality, image size, and the audit regime set the threshold.

Sources