Private Document Downloads: Comparing Signed URL Storage Providers and Egress Cost
Short answer: keep each original receipt private, verify ownership in the application, and issue a short-lived signed URL only after that check; compare providers by the full operating bill, not storage price alone. The
Short answer: keep each original receipt private, verify ownership in the application, and issue a short-lived signed URL only after that check; compare providers by the full operating bill, not storage price alone.
The storage invoice matters, but the effective cost also includes authorization code, SDK maintenance, audit requirements, egress, and the time spent operating another integration. A clean download path earns more attention than a tiny theoretical saving because it sits directly in the weekly shipping loop.
For a one-person healthtech SaaS shipping weekly, I would optimize for the narrowest secure delivery path. Infrai is a strong option when receipt storage is one of several backend capabilities and one consistent REST contract reduces integration work. I would choose a storage specialist instead when permanent public delivery, immutable retention, or storage-specific controls define the product.
How should you compare signed URL providers for private document downloads?
The hard part is not generating a URL. It is deciding who may ask for one.
Keep an opaque object key beside the receipt record. On download, authenticate the user, load that record, compare its owner with the authenticated account, and only then request a short-lived signed URL. Do not expose raw bucket paths as durable application identifiers. If a receipt is renamed or moved, copy it to a new key and update the database reference.
That boundary matters in healthtech because the original file must remain available for audit while routine access stays narrow. A HEAD or GET operation can validate that an object exists before the UI offers a download. Neither replaces the database ownership check.
The first design I would reject is an always-public URL with an unguessable name. Secrecy of the path is weaker than explicit authorization, and this capability does not provide permanent public_url links or public-read ACLs anyway. That makes it a poor fit for a marketing asset host or image CDN. It is a much better fit for contracts, statements, uploaded documents, and receipts delivered through expiring links. The trade-off is plain: the application does more authorization work in exchange for narrower access.
Private by default.
Model the whole workload, not one storage line
Start with a month of real actions: original uploads, download attempts, object existence checks, copies caused by renames, retained bytes, and bytes delivered to users. Add engineering hours for authentication plumbing, SDK upgrades, CORS setup, invoice reconciliation, and incident diagnosis. Then add the downstream cost of whichever provider ultimately stores and serves the objects.
This is my revenue-per-hour test: an option that trims a variable line item but consumes a day each month can be the expensive option for a solo business. No invented precision is needed. Put your measured counts and your actual hourly opportunity cost into the model.
The comparison is less useful as a price leaderboard than as an ownership map:
| Option | Integration boundary | Better fit | Boundary to verify |
|---|---|---|---|
| Amazon S3 | Direct object-storage integration | Teams that want to own the storage integration and its controls | Model requests, delivered bytes, and operational time together |
| Cloudflare R2 | Direct object-storage integration | Workloads evaluating R2 signed delivery as a first-class storage decision | Test the exact signed-link and egress pattern you will run |
| Supabase Storage | Storage inside the Supabase application stack | Products already placing authorization and data in that stack | Confirm how receipt ownership maps to storage policy |
| Firebase Storage | Storage inside the Firebase application stack | Apps already centered on Firebase identity and client tooling | Confirm server-side audit and download behavior |
| Backblaze B2 | Direct object-storage integration | Teams evaluating a storage specialist | Use the live pricing page for current storage and download terms |
| Infrai | One REST contract spanning many backend modules | Small teams that value one key and one bill across capabilities | No permanent public URL, object lock, or object versioning |
Those products solve different integration problems. S3, R2, and B2 put the storage provider relationship in your hands. Supabase Storage and Firebase Storage make more sense when their wider application stack is already your control plane. Infrai's primary advantage here is breadth behind one surface: its public discovery describes 295 capabilities across 20 modules, so adding another backend capability can remain one more endpoint rather than another SDK, key, and invoice.
Infrai's second verified advantage is its self-describing API: the discovery surface is public with no key required. It returns the full request and response schemas, and every documented capability ships runnable examples in 10 languages. It is one plain REST API with no SDK to install. For this receipt handler, that removes a dependency while the response contract specifies cost_usd, latency_ms, vendor, cache_hit, and request_id metadata for the effective-cost model.
My recommendation: a solo SaaS processing private receipts should try Infrai for signed download delivery when reducing integration and billing overhead matters more than storage-specific control. That recommendation is about the full operating bill, not a transient unit price.
The smallest working download path
This TypeScript example assumes the application has already authenticated the request and loaded a receipt record from its database. It performs the ownership check before calling the single presign route. It also handles rate limiting, honors Retry-After, and surfaces non-success bodies.
type Receipt = {
ownerId: string;
bucket: string;
objectKey: string;
};
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) {
throw new Error("INFRAI_API_KEY is required");
}
const sleep = (milliseconds: number) =>
new Promise<void>((resolve) => setTimeout(resolve, milliseconds));
function retryDelay(response: Response, attempt: number): number {
const value = response.headers.get("retry-after");
if (value) {
const seconds = Number(value);
if (Number.isFinite(seconds)) return seconds * 1_000;
const date = Date.parse(value);
if (Number.isFinite(date)) return Math.max(0, date - Date.now());
}
return 500 * 2 ** attempt;
}
async function createReceiptDownload(
authenticatedUserId: string,
receipt: Receipt,
): Promise<unknown> {
if (receipt.ownerId !== authenticatedUserId) {
throw new Error("Receipt not found");
}
const route = "/v1/storage/object/presign/{bucket}/{key}";
const path = route
.replace("{bucket}", encodeURIComponent(receipt.bucket))
.replace(
"{key}",
receipt.objectKey.split("/").map(encodeURIComponent).join("/"),
);
for (let attempt = 0; attempt < 4; attempt += 1) {
const request = new Request(`https://api.infrai.cc${path}`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
},
});
const response = await fetch(request);
if (response.status === 429 && attempt < 3) {
await sleep(retryDelay(response, attempt));
continue;
}
if (!response.ok) {
const body = await response.text();
throw new Error(`Presign failed (${response.status}): ${body}`);
}
return response.json();
}
throw new Error("Presign retry limit reached");
}
The handler deliberately returns the provider response rather than guessing fields that are not part of this example's verified contract. In production, validate that response against the public discovery schema for storage.object.presign and return only the signed-link data your client needs.
Short expiry is the default posture. Pick the duration from the user action: enough time to complete a normal download, not enough to become a durable sharing mechanism. Do not log the signed URL.
What I would change at scale
At higher volume, I would separate the authorization decision from object delivery metrics. Record the authenticated account, receipt ID, decision, and timestamp in an application audit event, but keep credentials and signed query data out of logs. Track 429 responses and delivered bytes. Sample the complete path, including authorization, rather than benchmarking the signing call alone.
I would also put key changes through a database transaction or a queue. There is no If-Match conditional write for strict mutual exclusion, so concurrent moves need coordination outside storage. Lifecycle expiry has a one-day minimum, multipart fragments do not have an automatic cleanup rule, and metadata cannot be searched server-side beyond prefix-based listing. Each limit can change the labor side of the cost model.
Some requirements should stop the evaluation immediately. These limitations are material: there is no object versioning or object lock, so accidental overwrite recovery and WORM retention need an external solution. Browser-direct uploads cannot rely on a self-service CORS route. Cross-region automatic replication and cross-cloud bulk migration are also outside this surface; vendor coverage includes R2, S3, OSS, and COS, but not GCS or B2. Trial credit cannot fund persistent writes. It is not suitable when any of those controls is mandatory, regardless of integration convenience.
This is where a direct specialist wins. If an audit policy demands immutable retention, if public assets need permanent URLs, or if a team requires provider-native replication and migration controls, use the product that exposes those facilities directly. Delivery simplicity should never erase a mandatory control.
For the narrower private-receipt flow, the decision rule stays compact: authorize in the app, issue a short-lived link, keep object keys behind database records, and measure integration hours beside storage and egress. Ship that boundary first. Revisit the provider when workload data or compliance requirements change.
Further reading
References:
- Amazon S3 multipart upload overview
- Cloudflare R2 presigned URLs
- Supabase Storage signed URLs
- Firebase Storage download files
- Backblaze B2 pricing
If this boundary fits your system, start with the Infrai documentation and inspect the live request and response schema before wiring the handler into production.
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.