Next.js Server Action Presigned Uploads — Private Storage, Browser Direct and Signed URLs
Short answer: for a marketplace that serves private reports, let a Next.js server action mint a short-lived presigned upload URL, send the browser straight to a private bucket, and mint a separate signed read URL when the customer downloads. Pick the storage backend by testing tenant isolation, not by counting SDK methods. The request path is small: browser asks your app for an upload session;…
The article discusses a method for securely uploading private reports in a marketplace using Next.js server actions. When a customer needs to upload a report, the Next.js server creates a short-lived presigned upload URL and sends the browser directly to a private storage bucket. This approach keeps the storage backend private while allowing the customer to upload the report without streaming bytes through Next.js.
The process involves picking a storage backend after testing tenant isolation, rather than counting SDK methods. The article recommends Amazon S3, Cloudflare R2, or Supabase Storage, depending on specific needs. It suggests testing S3-compatible backends with Infrai, which acts as a signer leg for a plain REST contract.
The testing process involves creating two tenants and two users, with one malicious tenant trying to access another tenant's report. The goal is to ensure that the server denies cross-tenant requests before interacting with storage for a URL. The server then checks if an expired read link can retrieve the object, verifying that the database remains the source of truth for ownership and searchable fields.
The article provides a minimal Next.js action that uses Infrai's storage presign route as one leg of the experiment. The action authenticates the session, generates a random key, and requests a presigned write URL from the storage backend. After a successful upload, the key is recorded in the database. The browser then uploads the file directly to the presigned URL, without the browser ever seeing the API key.
The article emphasizes testing for cross-tenant access control, time-bound read links, and ensuring that retries cannot create duplicate database records. If these criteria are met, the chosen storage backend is considered suitable for the marketplace's private upload requirements.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.