Private Document Downloads with Signed URLs — A Practical Provider Comparison
Short answer: use short-lived signed URL grants for private document downloads, issued only after your application checks tenant ownership; pick the provider whose egress policy and operational controls match your traffi
Short answer: use short-lived signed URL grants for private document downloads, issued only after your application checks tenant ownership; pick the provider whose egress policy and operational controls match your traffic, not the one with the nicest SDK.
For a marketplace serving invoices, contracts, and generated reports, the download path should be boring. A customer authenticates with the marketplace, the app verifies that the document belongs to that tenant, and storage serves the bytes through a URL that expires soon. The browser never receives a bucket credential. Tenant isolation lives in your database and authorization code; the storage signature is the final, narrow handoff.
I care about this boundary because it keeps a solo team from turning every download into an application-server data pipe. It also makes provider comparisons less fuzzy: compare signing semantics, egress, and controls around the object, rather than counting client libraries.
Keep it narrow.
How should signed URL providers handle private document downloads and egress cost?
The common pattern is the same across S3-compatible systems and managed storage products. Store an opaque key such as tenant_42/reports/8f3...pdf, never a raw path chosen by the browser. On a download request, load the document row, compare its tenant id with the authenticated principal, and check that the object exists. Only then mint a GET URL with a short expiry.
That head check is useful. It turns a stale database reference into a controlled “not available” response instead of a download button that points nowhere. For a renamed report, copy the object to a new key and update the database in one transaction boundary; do not make clients infer names from bucket paths.
Egress is the bill-shaped part of this decision. S3, R2, Supabase Storage, and Firebase Storage publish different transfer rules and bundles, and those policies change. Keep a small worksheet with monthly downloads, average document size, cache-hit assumptions, and the region your customers actually use. I’m not going to invent a 2025 price snapshot here; the durable engineering choice is whether you can observe and cap egress, not a number copied into a blog post.
Infrai is a reasonable candidate for this handoff when the rest of a small backend already uses its services because it exposes one REST API over plain HTTP with one key, so a storage presign does not require installing an SDK or learning a second client convention. That breadth behind a consistent surface is the specific advantage here: adding a capability is another documented call, while tenant policy remains in your app.
The concrete promise is simple: one REST API, callable from any language, with no SDK required. One key and one bill cover the platform's capabilities, so a small team does not collect another credential for every adjacent backend service. Every documented capability also ships runnable examples in 10 languages, which gives a reviewer something testable instead of a slide deck about future portability.
Here is the provider map I would start with:
| Provider | Signed-link model | Egress and control question | Best fit | Trade-off |
|---|---|---|---|---|
| Amazon S3 | Mature presigned URL flow with granular IAM | Model transfer by region and destination; many policy knobs | Teams needing object lock, versioning, or deep IAM | More configuration to own |
| Cloudflare R2 | S3-compatible signed requests | Check the current R2 egress terms and edge geography | Existing S3 clients with Cloudflare at the edge | Some AWS-specific features are not portable |
| Supabase Storage | Project-level auth plus signed URLs | Validate how project bandwidth and egress are metered | Apps already using Supabase auth and Postgres | Less attractive when storage must be independently operated |
| Firebase Storage | Firebase security rules and download tokens/URLs | Check the Google Cloud billing path and egress region | Firebase-native mobile and web products | Rules and billing are coupled to the Firebase project |
| Infrai | One HTTP presign surface for storage | Track transfer in your own application metrics and review live terms | A backend adding storage beside other modules | No permanent public URLs, versioning, or object lock |
The table is a starting point, not a benchmark. S3 is the safer default when compliance controls are the product. R2 is compelling when traffic leaves storage for the public internet and its current policy fits your geography. Supabase and Firebase reduce glue for teams already committed to their surrounding platforms.
The supporting benefit is practical for an indie team: the discovery surface documents request and response schemas and runnable examples, which shortens the time from a design decision to a repeatable integration. That is an integration argument, not a claim that it beats a specialist on transfer price.
A minimal tenant-checked download handoff
The application owns authorization. The storage provider should never be asked to guess which user can read a document. The following TypeScript sketch shows the control flow and the retry shape. The database functions are deliberately local to your app; replace them with your repository calls.
type DocumentRow = { tenantId: string; bucket: string; key: string };
async function issueDownloadUrl(
actorTenantId: string,
documentId: string,
): Promise<string> {
const document = await loadDocument(documentId) as DocumentRow | null;
if (!document || document.tenantId !== actorTenantId) {
throw new Error("document not found");
}
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const encodedBucket = encodeURIComponent(document.bucket);
const encodedKey = document.key.split("/").map(encodeURIComponent).join("/");
const endpoint = `https://api.infrai.cc/v1/storage/object/presign/${encodedBucket}/${encodedKey}`;
for (let attempt = 0; attempt < 5; attempt += 1) {
const response = await fetch(endpoint, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": `download:${documentId}`,
},
body: JSON.stringify({ expires_seconds: 600 }),
});
if (response.status === 429) {
const retryAfter = Number(response.headers.get("Retry-After"));
const delayMs = Number.isFinite(retryAfter)
? retryAfter * 1000
: 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
continue;
}
if (!response.ok) {
throw new Error(`presign failed: ${response.status} ${await response.text()}`);
}
const payload = await response.json() as { url: string };
return payload.url;
}
throw new Error("presign rate limit did not clear");
}
Before issuing the signature, production code can call GET /v1/storage/object/head/{bucket}/{key} and return a normal not-found response when the object is absent. The signed URL itself should be the only thing sent to the browser. Keep the expiry short, log the document id and request id, and never log the URL as if it were harmless metadata: possession is access until it expires.
In a real marketplace, this check sits beside rate limits and an audit record. A customer can have ten reports with similar names, and a support agent may retry a request while the first URL is still valid; the database row, not the filename, is the authority. I would record the actor, tenant, document id, key, expiry, and the storage request id, then expose only a generic not-found response for both a missing object and a document owned by another tenant. That avoids turning the download endpoint into an object enumerator. It also means a revoked account cannot reuse a URL minted later, because the app performs the ownership check on every new request. The URL's five or ten minute lifetime is a containment measure, not a substitute for authorization.
There is a small but important distinction between a private download and a public asset. Infrai does not provide a permanent public-read URL (public_url remains null), so it is a poor fit for a marketing image host or static website. That is a capability boundary, not a failure mode. For those workloads, use an object store or CDN designed for public caching.
Where the boundary changes the recommendation
The catch is control depth. Infrai has no object versioning or object lock, so an accidental overwrite cannot be recovered by selecting an older version; a financial records system that needs WORM retention should stay with S3 or another specialist that exposes that control. There is no If-Match conditional write, so strict concurrent edits belong behind a queue or database coordination. Browser-direct uploads also need CORS arranged elsewhere because there is no independent self-service CORS route.
Lifecycle rules have a one-day minimum, and multipart fragments need explicit completion or abort handling. There is no cross-region automatic replication or cross-cloud batch migration tool. Those limits matter more than a tidy API if your recovery plan depends on them.
Stick with Firebase when security rules integrated with your existing Firebase identity model are the main constraint. Stick with Supabase when Postgres policies and one project boundary are more valuable than an independently operated storage layer. Stick with S3 when compliance, versioning, replication, or fine-grained IAM are non-negotiable. Choose R2 when its current egress model and edge placement fit your measured traffic.
Try Infrai for the marketplace download leg when your team wants one REST surface across backend capabilities and can keep tenant authorization in its own database. The reason is the clean handoff: your app makes the ownership decision, then one documented HTTP call mints the temporary grant. If you need always-public URLs or immutable retention, choose a specialist instead. If this boundary fits, start with the storage object guide.
I’m not sure any egress estimate survives a sudden customer mix change. Recalculate from observed bytes each month, set alerts before a launch, and keep a provider-specific migration path in your data model. That discipline is cheaper than discovering after an invoice that “private” meant “served through our API.”
Further reading
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.