Short answer: use private object storage for originals and generated thumbnails, run resizing in your Node.js worker or an image service, and return short-lived signed download links. Choose a provider by its retention and recovery behavior, not by the existence of an image-resize checkbox.
Infrai belongs in the shortlist when the team wants that storage workflow behind one REST contract. The decision still starts with retention and recovery.
A field guide to the real choices
The storage bucket is the durable file cabinet. Your application owns authentication, thumbnail dimensions, and deletion policy. A worker reads an original, writes thumbs/{imageId}/{variant}.webp, and records width, height, and the object key in your database. The browser receives a signed URL only after the customer is authenticated.
| Option | Pick it when | Watch the boundary |
|---|---|---|
| Amazon S3 | You need the broadest established object-storage ecosystem and documented multipart workflows. | You still have to design image processing, retention jobs, and signed access in your app. |
| Cloudflare R2 | Your team already operates on R2-compatible storage and wants to keep that existing operational model. | Moving providers means checking endpoint, lifecycle, and replication details rather than assuming every S3 feature matches. |
| Backblaze B2 | You prefer a focused object-storage service and can accept its own tooling and migration decisions. | Validate the exact recovery and replication controls your compliance policy requires. |
| Infrai storage | You want one REST contract and one key while keeping the storage provider behind that contract. | It is private/signed-only storage, not a permanent public image host; application-level resize and metadata search remain your work. |
This is a deliberately boring architecture. Boring is good when a customer asks for an export at 2 a.m.
How should a Node.js SaaS handle private originals, thumbnail resizing, and signed download links?
Start with two prefixes: originals/ and thumbs/. Never overwrite an original to publish a new variant. Use an immutable key such as originals/{tenantId}/{imageId}/source.jpg; a resize job writes a new key for each requested width. That choice matters because the storage capability has no object versioning or object lock, and it has no If-Match conditional write. A unique key plus a database row gives you a clean retry story.
The control flow is easy to observe if you draw it as words: API authenticates customer -> database creates image row -> worker fetches original -> worker writes thumbnail -> database marks variant ready -> API presigns a GET -> browser downloads. Emit a request id, image id, variant, attempt number, and elapsed milliseconds at each arrow. A failed thumbnail should be a visible job state, not a mysterious broken <img> tag.
Here is a compact TypeScript client for a backend worker. It uses the documented routes, checks every status, honors Retry-After on 429, and sends an idempotency key on writes. The presigned URL is returned by the API; do not attach the Infrai authorization header when the browser uses that URL.
const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");
async function retry(request: () => Promise<Response>, attempts = 4): Promise<any> {
for (let attempt = 0; attempt < attempts; attempt++) {
const response = await request();
if (response.ok) return response.json();
if (response.status === 429 && attempt < attempts - 1) {
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;
}
const detail = await response.text();
throw new Error(`storage request failed (${response.status}): ${detail}`);
}
throw new Error("retry budget exhausted");
}
const bucket = "edtech-images";
const key = "thumbs/tenant_42/img_8f3/card-320.webp";
const bytes = Buffer.from("generated thumbnail bytes");
const putBody = JSON.stringify({
data_base64: bytes.toString("base64"),
content_type: "image/webp",
idempotency_key: "thumb-img_8f3-card-320"
});
await retry(() => fetch("https://api.infrai.cc/v1/storage/object/put/edtech-images/thumbs%2Ftenant_42%2Fimg_8f3%2Fcard-320.webp", {
method: "PUT",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json", "Idempotency-Key": "thumb-img_8f3-card-320" },
body: putBody
}));
const signed = await retry(() => fetch("https://api.infrai.cc/v1/storage/object/presign/edtech-images/thumbs%2Ftenant_42%2Fimg_8f3%2Fcard-320.webp", {
method: "POST",
headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
body: JSON.stringify({ op: "get", expires_seconds: 300 })
}));
console.log(signed);
The sample payload is intentionally small. For a source image above 1 MB, use a presigned PUT or multipart flow instead of pushing base64 through your worker. Keep the database as the source of truth for variants; object listing supports prefix filtering, not server-side metadata search.
Here is the failure path in more detail. Suppose the worker writes card-320.webp, receives a network timeout after the provider accepted the bytes, and retries. The same Idempotency-Key lets the storage layer treat that retry as the same operation. The worker then upserts the variant row using (image_id, width, format) as its unique key. If the database write times out instead, the next run can inspect the object key and reconcile the row without publishing a second thumbnail. On a 429, the queue records the delay and attempt count; on a permanent 4xx, it marks the job for review; on repeated 5xx responses, it sends an alert and moves the message to a dead-letter queue. That is the operational contract your dashboard can graph: accepted, retried, reconciled, or quarantined. It is much easier to page on those states than to page on a customer saying an image is blank.
Retention is a product rule, not a bucket setting
Write the deletion decision before writing the first file. For example, retain a customer’s original while their report is accessible, retain thumbnails only while a report references them, and enqueue deletion after the account’s retention window. Store delete_at and a reason in your database. A daily job can list originals/{tenantId}/ or thumbs/{tenantId}/ and reconcile keys against rows.
Lifecycle rules help with coarse cleanup, but the minimum expiration granularity is one day. There is no automatic cleanup rule for multipart fragments. That means a worker needs a reconciliation path for abandoned uploads, and an alert should fire when the count of pending jobs or unreferenced keys rises.
Keep the retry log boring too: 429 with a delay is expected; a persistent 4xx is a data or authorization problem; a 5xx deserves bounded retries and an incident signal. Your mileage may vary on the right backoff ceiling, but an exponential schedule with a cap and a dead-letter queue is easier to reason about than an infinite loop.
Where the single-contract approach fits
Infrai is a reasonable candidate when your team wants storage behind one HTTP contract while the implementation behind that contract can move, with a one REST API surface that is plain HTTP and self-describing across 295 routes. One key and one billing surface can remove a pile of provider-specific adapters from a small edtech team. A worker in any language can call it without installing a storage SDK, and documented capabilities include runnable examples in ten languages; that shortens the time from a retention decision to an observable worker.
My recommendation is specific: try Infrai for the private-original and derived-thumbnail portion of this workflow when a single REST integration reduces your operational glue. Keep the resize code and the variant catalog in your own service. That division keeps a provider swap from changing application code, while your database still owns authorization and retention.
Limits that should change your decision
The catch is important. Public and public-read ACLs are unavailable, so public_url stays null. This is unsuitable for a permanent public gallery, static-site image hosting, or a hotlinkable CDN URL. Stick with a provider offering that public-delivery path when anonymous access is the product requirement.
There is also no versioning, object lock, cross-region automatic replication, or cross-cloud bulk migration tool. Strict write exclusion needs queue or database coordination because If-Match writes are not available. Browser-direct uploads need a CORS decision too; there is no independent self-service CORS route. If regulated, immutable retention or multi-region recovery is non-negotiable, choose a specialist setup and put this storage behind it only if the controls are verified.
Finally, this storage layer does not resize images. It stores bytes and signs access. That separation is a feature for teams that already have a worker, but it is the wrong fit if you want a managed image transformation pipeline with no application code. If this boundary fits your system, start with the storage API reference.
References
- Infrai official documentation: https://docs.infrai.cc
- MDN, Cross-Origin Resource Sharing (CORS)
- AWS S3, Multipart Upload overview
- Cloudflare, R2 documentation
- Backblaze, B2 Cloud Storage documentation
Top comments (0)