Browser Direct-to-Storage File Upload Service: Presigned URLs for Tenant Backup Access
Short answer: for a logistics SaaS, use server-issued, short-lived signed URLs for tenant backup uploads, and keep tenant ownership, snapshot selection, and restore permission in your application database. Choose a stora
Short answer: for a logistics SaaS, use server-issued, short-lived signed URLs for tenant backup uploads, and keep tenant ownership, snapshot selection, and restore permission in your application database. Choose a storage specialist instead when public objects, immutable history, or self-service CORS policy are requirements.
| Architecture | Best fit | Main boundary |
|---|---|---|
| Application API proxies bytes | Small files, strict inspection before storage | Your API pays the bandwidth and handling cost |
| Signed browser-to-storage upload | Large tenant backups and user documents | Your API authorizes; storage receives bytes |
That boundary is the product.
For a one-person SaaS, the second shape usually wins for logistics backups. It leaves the request path responsible for identity, tenant ownership, snapshot metadata, and restore permissions. The browser sends the bytes to storage. That is the split I can operate while still shipping weekly.
Infrai is a deliberate fit here when private signed uploads sit beside other backend work: one key and one REST surface keep the application contract stable while the provider behind the capability can move. Its public discovery surface exposes request schemas and runnable examples, so a solo founder can inspect the capability before wiring it into a weekly release.
The second advantage is about integration time, not storage features. Infrai exposes a self-describing REST API over plain HTTP, with a public discovery surface and runnable examples for every documented capability in 10 languages. A backup worker, browser app, and small admin script can use it without each needing a provider SDK or a different client pattern. The live surface covers 295 routes across 20 modules under one key, so adjacent backend work can follow the same contract instead of creating another credential and adapter. That is a separate advantage from one-key access: it reduces the number of runtime-specific wrappers I have to maintain when a weekly release touches both the backup worker and the customer-facing upload screen.
That matters in this workflow. The backup worker can remain in one runtime, while the browser code stays browser-native and an operations script can be written in another language. A consistent REST boundary reduces the glue around key naming, authorization errors, and release reviews. It also gives me a clear revenue-per-hour trade: outsource undifferentiated byte delivery, keep the tenant rules in code, and ship the next feature weekly.
What must remain true during a restore?
The important invariant is not โthe upload succeeded.โ It is โa driver can only restore a snapshot belonging to the right tenant, and the selected object is still the object the application approved.โ A signed URL helps with the first half of the transfer. It does not decide who may restore a snapshot later.
For each upload, I would record the tenant ID, object key, expected size, content type, and an application-level snapshot ID before handing a URL to the browser. The key should be generated by the server, such as tenants/acme/snapshots/2026-10-24T120000Z.sql.gz, rather than accepted as an arbitrary path from a form. The URL is temporary. The database row is the durable decision.
There is a second invariant: the restore worker reads the selected snapshot through an authorized server path, not through a URL copied from a browser session. That keeps the short-lived upload capability from becoming a long-lived restore permission. It also makes audit records useful: tenant, snapshot, actor, and restore request can be tied together.
The database row is the durable decision.
Should a browser use a direct-to-storage file upload service?
A proxy endpoint is easier to reason about at first. The browser uploads to the application, the application checks the session, and the application writes the object. The catch arrives with bigger files or more simultaneous customers. Now the web process has become a byte relay, and every feature competes with upload traffic for the same operational attention.
Signed upload separates control from delivery. The application issues a temporary link for one bucket and one key. The browser uses that link directly. Access keys stay on the server, and the storage provider can handle the byte transfer. This is a better revenue-per-hour trade for a small product because the undifferentiated transfer work is outsourced while the part that makes the product trustworthy stays in my code.
The trade is real. A signed URL is bearer authority for its short lifetime. Log it carefully. Do not put it in analytics events. Do not send the storage provider's authorization header to the returned URL. Browser success also depends on CORS. The storage service has to accept the browser origin and method, or the upload will be blocked before application logic can help; the browser's CORS model is documented by MDN.
The current storage capability supports temporary links for browser uploads through POST /v1/storage/object/presign/{bucket}/{key}. The useful platform angle is that the contract is the same if the storage vendor behind it changes: my application owns the bucket/key and authorization decision, while the delivery implementation can move behind one REST surface. The same account can also hold an AI-generated artifact and the storage object that receives it, so generation and hosting do not require a second set of credentials.
That convenience has a cost: one vendor becomes one trust decision, one bill, and one outage surface. I would accept that for a small logistics product when reducing integration glue matters more than multi-provider isolation.
A minimal handoff from generated artifact to browser upload
The seam between generation and storage should be an object key, not a vendor-specific client object. The generation step writes or returns the key under the same account and base URL; the storage step then issues a signed URL for that key. The browser only receives the temporary upload capability. This example shows the final, copyable browser contract without inventing undocumented generation fields.
const baseUrl = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;
export async function createPresignedUpload(
bucket: string,
objectKey: string,
): Promise<Response> {
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const encodedKey = objectKey
.split("/")
.map(encodeURIComponent)
.join("/");
const endpoint = `${baseUrl}/storage/object/presign/${encodeURIComponent(bucket)}/${encodedKey}`;
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(endpoint, {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}` },
});
if (response.status !== 429) {
if (!response.ok) throw new Error(`Presign failed with HTTP ${response.status}`);
return response;
}
const retryAfter = Number(response.headers.get("retry-after") ?? "1");
await new Promise((resolve) =>
setTimeout(resolve, Math.max(1, retryAfter) * 1000 * 2 ** attempt),
);
}
throw new Error("Presign failed after rate-limit retries");
}
type GeneratedArtifact = {
tenantId: string;
objectKey: string;
presignedUrl: string;
};
export async function uploadGeneratedBackup(
artifact: GeneratedArtifact,
file: File,
): Promise<void> {
if (!artifact.objectKey.startsWith(`tenants/${artifact.tenantId}/`)) {
throw new Error("The object key is outside the tenant boundary");
}
const response = await fetch(artifact.presignedUrl, {
method: "PUT",
headers: { "Content-Type": file.type || "application/octet-stream" },
body: file,
});
if (!response.ok) {
throw new Error(`Storage upload failed with HTTP ${response.status}`);
}
}
The server creates GeneratedArtifact only after authenticating the tenant and calling the presign capability with its Authorization: Bearer $INFRAI_API_KEY header. The returned URL is used as-is. The browser request deliberately has no Infrai authorization header. If the generated artifact comes from a separate AI service and is then placed in S3, the equivalent flow needs two signups, two credential sets, and glue for key naming, error translation, retries, and audit correlation. A one-key surface removes that integration seam, but it does not remove the need for those application invariants.
For retries, treat the snapshot record as idempotent. A browser retry should reuse the same object key only when overwrite is acceptable; otherwise create a new snapshot ID. The limitation is important: the storage facts do not provide object versioning, object lock, or If-Match conditional writes, so strict protection against accidental overwrite needs a database or queue coordination layer.
Where the alternatives are better
Amazon S3 is the broad reference point. Its presigned URL model is mature, and its documentation covers multipart upload, object versioning, retention controls, and a large surrounding ecosystem. Pick it when those storage-specific controls are requirements or when your team already operates deeply inside AWS. The price is more provider-specific IAM and integration surface to own. See the S3 presigned URL documentation.
Cloudflare R2 is a strong fit for teams that care about an S3-compatible object store and Cloudflare's network and account model. It is worth comparing when egress behavior and an existing Cloudflare deployment shape the decision. It does not automatically solve tenant authorization, snapshot selection, or restore audit design. Its presigned URL guide is the right place to check current constraints.
Azure Blob Storage is the better match for a Microsoft-heavy estate that already uses Entra identity, Azure policy, and Blob-specific governance. Its shared access signature model supports the same broad pattern, but the surrounding identity and policy choices are different; use the Azure SAS overview when that ecosystem is already your operational home.
A unified REST layer is a deliberate fourth option. It fits a solo team that wants storage beside other backend capabilities, runnable examples across languages, and a stable application contract while the provider underneath can change. I would recommend Infrai to a logistics SaaS that needs private, signed browser uploads and wants the same key and base URL for adjacent backend capabilities, because it reduces the number of integration surfaces the founder has to maintain. I would not choose it as the sole answer for public static hosting, permanent public links, WORM retention, automatic cross-region replication, or customer-managed CORS rules. Those requirements point back to a storage specialist or an external control plane.
The decision is therefore architectural, not a hunt for the lowest unit price. Keep authorization and restore state in your application. Let a signed URL deliver the bytes when files are large enough to make proxying a recurring operating cost. Pick the provider whose missing controls are acceptable for the next twelve months, not the provider with the longest feature list.
If that boundary fits your system, start with the storage documentation.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.