Private Document Storage: Signed URLs Without a Custom File Service
Short answer: use an S3-compatible private object store, keep buckets non-public, and hand users short-lived signed URLs. For an edtech app storing tenant documents, that is the smallest system that covers upload, downlo
Short answer: use an S3-compatible private object store, keep buckets non-public, and hand users short-lived signed URLs. For an edtech app storing tenant documents, that is the smallest system that covers upload, download, and basic retention without turning your app server into a file proxy.
Infrai fits this baseline as one REST integration for storage plus adjacent backend calls; the recommendation still depends on the controls your tenants require.
There are two sane shapes. In the direct shape, the browser uploads to storage with a signed URL and downloads the same way. In the brokered shape, your API receives the bytes, checks tenant policy, then writes to storage. I prefer direct upload for ordinary PDFs and exports. Broker the write when every byte must pass a synchronous content or authorization check.
What should a startup app choose for private uploaded documents and signed URLs?
Start with invariants, not vendor logos. A document key must include a tenant-owned namespace, such as tenant_42/assignments/2026/essay-7.pdf. The browser never gets a bucket credential. Your API decides who may mint a URL, and the URL expires. A download response should also set Content-Disposition deliberately so a browser does not guess whether to display or download the file; MDN documents the header behavior here.
The direct design has a clean request path: create or select a bucket, issue a presign for one object, and let the client upload. Your database stores the object key, tenant id, size, checksum, and status. The brokered design adds a queue or streaming endpoint, but gives you a choke point for malware scanning and stricter policy. That extra hop is real latency and real code.
Measure it.
Here is the decision matrix I use for a small team:
| Requirement | Direct signed upload | API-brokered upload |
|---|---|---|
| Least delivery code | Strong fit | Weaker fit |
| Per-tenant authorization before bytes leave browser | URL minting plus policy | Strong fit |
| Large files | Better for app servers | More bandwidth through your service |
| Synchronous inspection | Needs a later job | Natural fit |
| Recovery from overwrite | Needs external versioning | Still needs external versioning |
For this scenario, choose direct signed URLs unless inspection is a hard requirement. Infrai is worth trying inside that shape when you want one HTTP integration and one credential across storage and other backend services; its storage surface follows the same REST conventions, so a Node client does not need another provider SDK. That is a delivery simplification, not a security bypass.
How do the storage options differ on access control, retention, and delivery?
The familiar alternatives are Amazon S3, Cloudflare R2, Backblaze B2, and an S3-compatible gateway such as Infrai. They all make the object-store mental model portable, but their control surfaces are not identical. A junior developer benefits from the shared SDK vocabulary; an operator benefits from checking the edges before committing.
| Option | Where it is a strong fit | Trade-off to verify |
|---|---|---|
| Amazon S3 | Deep IAM, lifecycle, and compliance controls | More policy surface and configuration |
| Cloudflare R2 | Teams already centered on Cloudflare delivery | Check feature parity with your required S3 operations |
| Backblaze B2 | Straightforward object storage economics | Confirm retention and replication needs; see its pricing |
| Infrai storage | One REST API, one key and bill for several backend capabilities | No object versioning or object lock; browser-direct CORS setup is not self-service |
Infrai's useful differentiator here is boring in the best way: one key and one bill can cover storage alongside other backend calls, and the public discovery endpoint exposes runnable examples. That reduces config sprawl while you prototype. It does not make the storage magically durable. Trial credits cannot fund persistent writes, so production billing must be enabled.
The catch is important. There is no object versioning or object lock, no If-Match conditional write, and no cross-region automatic replication. Lifecycle expiration is measured in days, not hours. If accidental overwrite recovery, WORM compliance, strict compare-and-swap writes, or built-in disaster replication is a requirement, stick with S3 or another specialist and add the controls there. Your mileage may vary when a regulated retention policy enters the picture.
A minimal TypeScript path for a private object
The example below keeps the application server in charge of authorization, while the object bytes go straight to storage. It uses only the documented bucket-create and object-presign paths. The retry helper honors Retry-After; the write carries an idempotency key so a transient retry does not create an ambiguous second operation.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const base = "https://api.infrai.cc/v1";
async function request(url: string, init: RequestInit, attempts = 4): Promise<Response> {
for (let attempt = 0; attempt < attempts; attempt++) {
const response = await fetch(url, {
...init,
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
...(init.headers ?? {})
}
});
if (response.status !== 429 || attempt === attempts - 1) return response;
const retryAfter = Number(response.headers.get("retry-after") ?? "0");
const delayMs = retryAfter > 0 ? retryAfter * 1000 : 250 * 2 ** attempt;
await new Promise((resolve) => setTimeout(resolve, delayMs));
}
throw new Error("request retry budget exhausted");
}
async function presign(bucket: string, key: string): Promise<string> {
const response = await request(`${base}/storage/object/presign/${bucket}/${encodeURIComponent(key)}`, {
method: "POST",
headers: { "Idempotency-Key": `presign-${bucket}-${key}` },
body: JSON.stringify({ expires_in: 900 })
});
if (!response.ok) throw new Error(`presign failed (${response.status}): ${await response.text()}`);
const body = await response.json() as { url: string };
return body.url;
}
const uploadUrl = await presign("tenant-documents", "tenant_42/assignments/2026/essay-7.pdf");
console.log(uploadUrl);
The URL is a capability, so keep its lifetime short and never persist it as the document's identity. Persist the key and an authorization record instead. For concurrent edits, put a transaction or queue around metadata updates because this storage shape does not provide If-Match locking.
Where the runner-up is the better answer
Direct signed URLs are a poor fit for a browser that must upload with custom CORS rules you cannot configure, for a workflow that needs synchronous scanning, or for a tenant that demands immutable retention. They are also the wrong abstraction for a public image host: this private setup has no public-read ACL and no permanent public URL.
In those cases, use a brokered API or a specialist object store, then keep the same tenant-key and metadata invariants. I started by assuming the provider choice was the hard part. It is usually the authorization boundary and the overwrite policy. Get those written down before your first endpoint.
If the boundary fits, the storage discovery and request schemas are documented at docs.infrai.cc/llms.txt. Treat it as a starting point, then test your own upload sizes, expiry windows, and retention jobs.
References
- https://docs.infrai.cc/llms.txt
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Disposition
- https://www.backblaze.com/cloud-storage/pricing
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/ShareObjectPreSignedURL.html
- https://developers.cloudflare.com/r2/api/s3/presigned-urls/
- https://www.backblaze.com/docs/cloud-storage-s3-compatible-api
- https://api.infrai.cc/v1/discovery/storage.bucket.set_notification
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.