Next.js Receipt Storage: Auditable Private Browser File Uploads A developer describes a Next.js receipt-upload architecture for healthtech claims that separates write authorization from byte delivery: a server action authenticates the caller, authorizes the claim, creates a pending receipt row with a server-generated object key, and returns a short-lived upload grant so the browser writes directly to private object storage. A separate completion check transitions the receipt from pending to ready before any OCR or LLM parser can consume it, keeping the original immutable as audit evidence and recording an integrity value with each processing job. Short answer: treat the Next.js server action as a short-lived authorization decision, not as the file pipe. Let the browser upload the receipt directly to private object storage, then make a separate completion check before any parser or reviewer can use the original. That design keeps the audit boundary visible: the action decides who may write, storage holds the bytes, and the database records what was actually accepted. For a healthtech receipt workflow, delivery simplicity is tempting. A browser posts a file, the server saves it, and an OCR or LLM job starts. The failure is subtle: a successful authorization request is not proof that the bytes arrived, and a successful parse is not proof that the original can be retrieved later. My decision axis is reliability under audit, not the shortest demo. The failure usually appears later. Imagine an auditor opening claim claim-1842 after a busy week. The database says the receipt was parsed, but the browser closed after receiving its upload grant; a queue retry saw the pending row and treated the object key as if it were an accepted file. In a different run, the bytes arrived but completion was called twice, producing two processing jobs with different derived totals. In a third, the reviewer still had a signed read from before their access changed. None of these cases is fixed by making the upload button prettier. They require separate write authorization, object acceptance, processing eligibility, and read authorization, each tied to the same receipt id and each visible in an audit record. That is the boundary I would review before measuring latency or storage cost. I've learned to ask one unfashionable question early: what exact event lets us say "this original is preserved"? Until that answer is recorded, the receipt is an upload attempt. A receipt row should exist before the browser sends bytes. Give it a server-generated object key, an owning user or claim, declared content type, declared byte count, and a state such as pending , ready , or expired . Store the display filename as metadata. Do not use an untrusted filename as the object path; slashes, control characters, and duplicate names turn a friendly field into an awkward authorization surface. The state machine makes the workflow testable: type ReceiptState = "pending" | "ready" | "expired"; type Receipt = { id: string; claimId: string; ownerId: string; objectKey: string; contentType: string; declaredBytes: number; state: ReceiptState; }; function canParse receipt: Receipt : boolean { return receipt.state === "ready"; } pending means permission was issued and work may still be incomplete. ready means the application has checked the expected object and accepted the transition. expired means the session was abandoned or aged out and must not enter the parser queue. This is a small distinction with a large payoff: a worker never has to infer business truth from the presence of a URL. The original file is evidence. Extracted merchant names, totals, and model output are derived records. Keep the source object immutable for the audit path, and record the object key plus an integrity value with each processing job. If a model run needs to be repeated, it should read the same accepted source rather than replacing it with a newly rendered preview. The action should do four things in order: authenticate the caller, authorize the claim, create the pending row, and return an exact upload grant. The grant contains the method, URL, and required headers produced by the storage adapter. The browser uses those values as returned. It does not construct a provider-specific request or receive the credential that created the grant. The application-facing function can stay deliberately boring. Its name is an application contract, not a claim about a framework route or storage provider: type UploadGrant = { receiptId: string; objectKey: string; request: { method: "PUT" | "POST"; url: string; headers: Record