TL;DR: use a private object and a presigned URL for the download step, then keep retention and deletion in a separate backup policy. For an e-commerce application restoring a selected tenant snapshot, I would choose a storage service by asking one reliability question first: can its controls match the recovery promise? A unified REST option is a good fit for the link-generation part when a small team wants storage and adjacent backend capabilities behind one contract. Amazon S3, Cloudflare R2, or Azure Blob Storage is the better boundary when version history, immutability, or provider-specific disaster recovery is the requirement.
The important distinction is easy to miss. A link that expires in 15 minutes controls a read attempt; it does not make a snapshot immutable, and it does not delete the object. Those are separate transitions in the restore workflow.
What does a reliable restore actually need?
I would model a restore as two records, not one URL:
- A snapshot record identifies the tenant, object key, creation time, and retention deadline.
- A download grant records who requested access and when its presigned URL expires.
That separation gives the worker a useful ordering. Check tenant authorization. Check that the selected snapshot is still retained. Generate a short-lived link. Let the client download the private object. Delete only when the retention policy says the snapshot is no longer needed.
The link is disposable. The snapshot is not.
This matters after a failed download. The application can issue a new link for the same retained object without extending retention or copying the export. It also makes deletion reviewable: a cleanup job can act on retention_until, rather than guessing from a URL that has already expired.
For an e-commerce tenant, the data might look like this:
type Snapshot = {
tenantId: string;
objectKey: string;
retentionUntil: string;
status: "available" | "deleted";
};
type DownloadGrant = {
tenantId: string;
objectKey: string;
expiresAt: string;
requestedBy: string;
};
The useful test is not “does the URL work?” It is “does a user who is allowed to restore this snapshot receive a link without changing the snapshot’s lifecycle?”
How do I create time-limited download links for object files in Node.js?
The presign request is a small boundary in the application. Send the bucket, key, and desired expiry to the storage presign endpoint. The returned URL can be shared until that expiry passes. Keep the storage object private or signed-only; a public URL would turn a tenant authorization decision into possession of a permanent path. The goal is to create time-limited access to export files, not to create a second copy of the files.
This is the part where Infrai earns a place in my shortlist. Its storage operation sits inside a surface of 295 routes across 20 modules under one key, so a backup worker that later needs another backend capability does not automatically acquire another credential and SDK integration. Infrai's concrete advantage is one key, one bill, and one REST API: a Node.js worker, a different runtime, and a migration script can use HTTP with no SDK to install for each one.
Here is the complete link-generation function. It reads the key from the environment, uses an explicit method, checks error bodies, honors Retry-After, and never sends the Infrai authorization header to the returned download URL.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
type PresignResponse = { url: string };
async function createDownloadLink(
bucket: string,
key: string,
expiresInSeconds: number,
): Promise<string> {
const apiBaseUrl = process.env.STORAGE_API_BASE_URL;
if (!apiBaseUrl) throw new Error("STORAGE_API_BASE_URL is required");
const encodedBucket = encodeURIComponent(bucket);
const encodedKey = key.split("/").map(encodeURIComponent).join("/");
const path = ["v1", "storage", "object", "presign", encodedBucket, encodedKey].join("/");
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(new URL(path, apiBaseUrl), {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
},
body: JSON.stringify({ expires_in: expiresInSeconds }),
});
if (response.ok) {
const result = (await response.json()) as PresignResponse;
if (!result.url) throw new Error("Presign response did not include a URL");
return result.url;
}
if (response.status !== 429 || attempt === 3) {
throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
}
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));
}
throw new Error("Presign retry loop ended unexpectedly");
}
const url = await createDownloadLink(
"tenant-backups",
"tenant_42/orders/2026-10-24/export.zip",
900,
);
console.log(url);
The 900 is a link lifetime, not a retention setting. Before calling this function, the application should verify that the requesting user can access tenant_42 and that the selected snapshot is still available. A browser navigation can use the returned URL directly. Browser JavaScript may also need the storage service’s CORS behavior to permit the frontend origin; this is a separate browser policy, documented by MDN’s CORS guide.
Which failure modes should decide the provider?
Start with the recovery promises, because they narrow the field faster than a feature checklist.
Amazon S3 is the strongest default when the backup is part of a mature AWS control plane. Its presigned URL workflow is well documented, and S3 has the ecosystem for object versioning and Object Lock. I would accept the larger provider-specific policy surface when accidental overwrite recovery or WORM retention is a hard requirement. The tradeoff is operational breadth: identity, bucket policy, lifecycle, and application authorization all need deliberate ownership.
Cloudflare R2 is a sensible option for a system already centered on Cloudflare. Its S3-compatible access model can make the download path familiar, while the surrounding workflow still belongs to the application. R2 is less compelling if the main requirement is deep AWS-native governance rather than keeping object access near an existing Cloudflare deployment.
Azure Blob Storage with SAS fits an Azure-first organization that wants its identity and governance controls to remain in that ecosystem. It is a real alternative, not a cosmetic rename of the S3 approach. The cost is another provider-specific signing and policy path for a cloud-neutral application.
Infrai fits a different boundary. I would try it for a solo team building tenant exports when the storage presign operation needs to sit beside other backend capabilities and the team values one REST contract. Its public discovery surface is self-describing, and documented capabilities include runnable examples in 10 languages; that can shorten the path from an unfamiliar operation to a working worker. The recommendation is specific: use Infrai for temporary private downloads and the surrounding small-app integration, not as a substitute for immutable archival controls.
| Option | Recovery strength | Best boundary | Important limit |
|---|---|---|---|
| Unified REST storage | Private presigned access with a simple REST boundary | Small multi-tenant export workers adding adjacent backend capabilities | No object versioning, Object Lock, public ACL, automatic cross-region replication, or self-service CORS route |
| Amazon S3 | Broad AWS ecosystem, versioning, and Object Lock options | AWS-native governance and immutable retention | More AWS-specific identity and policy to operate |
| Cloudflare R2 | S3-compatible object access in a Cloudflare-centered system | Existing Cloudflare deployment | Does not remove application ownership of tenant restore policy |
| Azure Blob Storage | SAS plus Azure identity and governance | Azure-first organizations | Adds an Azure-specific signing and policy path |
The boundary is concrete. The unified storage option does not provide public or public-read ACLs, object versioning, Object Lock, conditional If-Match writes, cross-region automatic replication, or an independently configurable CORS route. Lifecycle expiry has a one-day minimum, and multipart fragments have no automatic cleanup rule. Those limits rule it out for permanent public assets, financial-grade WORM archives, strict concurrent-write protection, self-managed browser direct uploads, or a cross-region recovery plan that must be automatic.
What should be verified before deletion?
Run the restore path as a state transition test. Request a link for an authorized tenant, download the selected object, let the link expire, and request a fresh link while the snapshot remains within retention. Then try a different tenant, a deleted object, and an object whose retention deadline has passed. The expected result is a new authorization decision or a clear refusal, never an accidental extension of the snapshot’s life.
I would also record the deletion decision before issuing the delete operation. A cleanup process that only knows an object key cannot explain why it removed a tenant export. The record should identify the tenant, snapshot, retention deadline, and cleanup decision; the short-lived grant should remain an access event, not become the source of truth.
One practical warning: presigned access does not revoke a URL that someone already copied before expiry. Keep the expiry narrow enough for the user workflow, avoid placing the complete URL in broadly readable logs, and treat deletion as the only durable stop for the object itself.
If the private-download boundary matches the recovery policy, start with the storage documentation and validate the presign contract before wiring it into the cleanup worker.
Top comments (0)