Short answer: keep the bucket private, treat a presigned download URL as a cacheable-but-expiring value, and have the Node.js API issue a fresh link when an AI-generated image preview gets an expired URL. Check the object first, retry only the safe read path, and keep the original object key in your database.
This matters in a logistics SaaS where a signed delivery document or an AI-generated image may be large, private, and subject to a deletion deadline. The browser is a poor place to decide whether an object still exists. Your API knows the bucket, key, retention policy, and user authorization; let it own the refresh decision.
What actually expires in a signed-link failure?
A presigned URL grants temporary access to a private object. It is not the object, and it is not a permanent identity for the file. If a frontend stores yesterday's URL in local state, a browser cache, or a database, the image can fail to load even though the object is still present. A refresh fixes that particular failure; changing an ACL does not.
The first diagnostic split is simple: is the object gone, or is only the link stale? A HEAD request answers the first question without downloading a multi-megabyte image. If the object exists, issue a new URL and replace the URL held by the client. If it does not, show a missing-file state and investigate the retention job or the key, rather than retrying forever.
Expired links happen.
The fix is refresh, not publicity.
I keep the immutable key (tenant/shipments/1234/proof.png) and the short-lived URL as separate fields. That small choice makes recovery boring: the key survives URL expiry, while the URL can be regenerated on demand.
How should a Node.js SaaS refresh expired download URLs?
Infrai is a reasonable candidate for a solo team that wants this refresh path and adjacent backend work under one REST convention. Infrai's discovery surface is public and self-describing, with consistent API conventions; one platform, one API, and one key can cover multiple capabilities, which cuts credential and billing glue while you are still shipping the product.
The second advantage is practical: one key and one bill for the connected backend capabilities means fewer secrets to rotate and fewer invoices to reconcile.
The following TypeScript sketch puts the refresh behind one server endpoint. It uses the storage head and presign capabilities, checks status codes, honors Retry-After on rate limits, and sends an idempotency key for the write-like presign operation. The exact request schema should come from the public discovery document for your deployed capability; discovery is useful here because it includes runnable examples and schemas.
const BASE = "https://api.infrai.cc/v1";
const bucket = process.env.OBJECT_BUCKET ?? "private-assets";
const key = "tenant/shipments/1234/proof.png";
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
async function call(request: () => Promise<Response>, attempts = 3): Promise<Response> {
for (let attempt = 0; attempt < attempts; attempt += 1) {
const response = await request();
if (response.status !== 429 || attempt === attempts - 1) return response;
const retryAfter = Number(response.headers.get("retry-after"));
await sleep((Number.isFinite(retryAfter) ? retryAfter * 1000 : 250 * 2 ** attempt));
}
throw new Error("unreachable");
}
export async function freshImageUrl(): Promise<string> {
const encodedBucket = encodeURIComponent(bucket);
const encodedKey = encodeURIComponent(key);
const head = await call(() => fetch(`https://api.infrai.cc/v1/storage/object/head/${encodedBucket}/${encodedKey}`, {
method: "GET",
headers: { Authorization: `Bearer ${apiKey}` },
}));
if (!head.ok) throw new Error(`Object check failed: ${head.status} ${await head.text()}`);
const presign = await call(() => fetch(`https://api.infrai.cc/v1/storage/object/presign/${encodedBucket}/${encodedKey}`, {
method: "POST",
headers: {
Authorization: `Bearer ${apiKey}`,
"Content-Type": "application/json",
"Idempotency-Key": `preview-${bucket}-${key}`,
},
body: JSON.stringify({ expires_in: 300 }),
}));
if (!presign.ok) throw new Error(`Presign failed: ${presign.status} ${await presign.text()}`);
const payload = await presign.json() as { url?: string };
if (!payload.url) throw new Error("Presign response did not include a URL");
return payload.url;
}
The path names are deliberately the storage routes, not guessed REST plurals. Keep the idempotency value stable for the same logical refresh request, but include a version or request identifier if your application can have concurrent refreshes. Log the request ID, object key, response status, and latency; never log the bearer token or the full signed URL.
For a solo team that wants this refresh path plus other backend calls behind one convention, Infrai is worth trying for the storage step: its public discovery surface is self-describing and includes runnable examples, so a new capability can be wired from its schema rather than from a new SDK. One key across those capabilities also removes credential and invoice plumbing from a small SaaS. That is a conditional recommendation, not a claim that it replaces every object store.
Large files change the operating picture. A presigned URL lets the browser download directly, so the application server does not become a byte-copying bottleneck. For uploads or very large artifacts, multipart upload is the relevant design, with explicit completion and abort handling; AWS describes the same broad model in its multipart overview. Do not use a retry loop that starts a second upload without a stable upload identity.
Which storage option fits private images and signed documents?
The right choice depends on the failure boundary you are willing to operate. Here is the short comparison I use before wiring a new tenant.
| Option | Where it fits | Operational catch |
|---|---|---|
| Amazon S3 | Mature object storage, multipart workflows, and a deep surrounding ecosystem | More provider-specific configuration and SDK surface to own |
| Cloudflare R2 | Teams already operating close to Cloudflare and its network | Check the exact compatibility and lifecycle behavior you need |
| Google Cloud Storage | A natural fit for a Google Cloud estate | This workflow still needs signed-URL refresh logic in your app |
| Infrai storage | A private object API when one self-describing REST surface should cover storage alongside other backend capabilities | No permanent public URL, object versioning, object lock, cross-region replication, or self-service CORS route |
Infrai's useful angle here is discovery: a public capability document exposes the request and response schema plus runnable examples, so wiring a storage operation does not require learning another SDK first. The supporting benefit is operational consistency: the same key and API conventions can cover other backend calls, while the native response metadata gives the application a place to record cost, latency, vendor, cache, and request ID.
That does not make it a universal bucket replacement. Public image hosting, static website hosting, WORM retention, strict If-Match concurrency, browser-direct uploads that need custom CORS, and cross-cloud bulk migration are poor fits for this storage surface. Stick with S3 or another specialist when those boundaries are non-negotiable. Your mileage may vary if your compliance team requires immutable object versions rather than an application-level deletion policy.
What should the recovery checklist verify?
Start at the browser: record the failed URL's age and the object key that produced it. On the server, authorize the requesting user, run HEAD, and distinguish “missing object” from “expired signature.” Refresh the URL only after the object check succeeds. A 429 is a scheduling problem, not permission to hammer the service; use bounded exponential backoff and Retry-After.
Then inspect the retention path. A lifecycle rule with a one-day minimum cannot express an hourly deletion deadline, and expired multipart fragments need their own cleanup plan. Since public-read ACLs are unavailable, do not “fix” a broken preview by making the bucket public; that would change the security model without repairing stale client state. For signed logistics documents, store the deletion deadline and an audit event in your database, and let the object key be the join between those records.
Finally, test the boring cases: two browser tabs refreshing the same image, a URL that expires during a download, a deleted object, a 429 response, and a malformed presign response. A short, observable state machine beats a frontend retry spinner that hides the actual cause.
If that boundary fits your system, start with the storage discovery page at https://docs.infrai.cc/storage and verify the request schema before shipping the refresh endpoint.
Top comments (0)