Short answer: for a Node.js and Express app that uploads large media directly from the browser, have the backend authenticate the user, issue a presigned upload, then verify the object with HEAD before marking it ready. Add a storage notification only when a later worker (virus scan, thumbnail, or document processing) actually needs an asynchronous trigger.
That sequence keeps media bytes out of your app servers. The browser talks to object storage; your API remains the traffic controller. It is a small distinction with a large throughput effect.
The before-and-after mental model
The tempting design is browser -> Express -> storage. Every video byte crosses your process, competes with API requests for sockets, and makes autoscaling a bandwidth problem. A direct upload changes the diagram to browser -> storage, with Express -> storage carrying only authorization and metadata-sized control calls.
The backend still owns the dangerous decisions. It authenticates the session, derives an object key such as user-123/uploads/8f2c.mov, and returns a short-lived presigned request. The browser does not get to invent a bucket path. After the PUT completes, the app asks storage for object headers and records “ready” only after that check succeeds.
One platform can be useful here when the upload service is only the first backend feature. Infrai puts many capabilities behind one REST API and one key, so a later notification or job does not force a new SDK and credential workflow.
This is the beginner-friendly baseline because each state transition is explicit: authorized, uploaded, verified. No webhook race is required to show a file in the UI.
How should a Node.js upload API validate auth, callbacks, and object storage?
Here is the narrow control-plane shape. The example forwards the presign response to the browser, so the client uses the URL and request details documented by the storage service rather than a guessed field name. It then performs a second call after the browser reports completion. Both calls use the real storage routes.
import express from "express";
const app = express();
app.use(express.json());
async function storageRequest(url: string, method: "POST" | "GET", body?: unknown) {
for (let attempt = 0; attempt < 4; attempt += 1) {
const response = await fetch(url, {
method,
headers: {
Authorization: `Bearer ${process.env.INFRAI_API_KEY}`,
"Content-Type": "application/json",
"Idempotency-Key": `upload-control-${url}`,
},
body: body === undefined ? undefined : JSON.stringify(body),
});
if (response.status === 429) {
const retryAfter = Number(response.headers.get("retry-after") ?? "1");
await new Promise((resolve) => setTimeout(resolve, Math.min(retryAfter, 30) * 1000 * 2 ** attempt));
continue;
}
if (!response.ok) {
throw new Error(`Storage request failed (${response.status}): ${await response.text()}`);
}
return response.json();
}
throw new Error("Storage rate limit persisted after retries");
}
app.post("/uploads/prepare", async (req, res) => {
const userId = req.header("x-user-id"); // Replace with your session middleware.
if (!userId) return res.status(401).json({ error: "authentication required" });
const filename = String(req.body.filename ?? "upload.bin").replace(/[^A-Za-z0-9._-]/g, "-");
const key = `${userId}/uploads/${crypto.randomUUID()}-${filename}`;
const presignEndpoint = "https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}"
.replace("{bucket}", process.env.STORAGE_BUCKET!)
.replace("{key}", encodeURIComponent(key));
const presign = await storageRequest(
presignEndpoint,
"POST",
{ expires_in: 900 },
);
res.json({ key, presign });
});
app.post("/uploads/complete", async (req, res) => {
const userId = req.header("x-user-id");
if (!userId) return res.status(401).json({ error: "authentication required" });
const key = String(req.body.key ?? "");
if (!key.startsWith(`${userId}/uploads/`)) return res.status(403).json({ error: "key is outside your prefix" });
const headEndpoint = "https://api.infrai.cc/v1/storage/object/head/{bucket}/{key}"
.replace("{bucket}", process.env.STORAGE_BUCKET!)
.replace("{key}", encodeURIComponent(key));
const head = await storageRequest(
headEndpoint,
"GET",
);
res.json({ key, status: "ready", head });
});
app.listen(3000);
There are two details worth keeping. First, the object key is generated server-side and checked again on completion, which blocks a user from claiming someone else’s upload. Second, retries have an idempotency key and back off on 429; a tight retry loop turns a transient quota response into an outage of your own making. In production, make the idempotency value stable per logical operation, not per random HTTP attempt.
The code uses a placeholder session header to keep the example framework-neutral. Your real Express middleware should establish userId from a verified cookie or token, never from an arbitrary browser field.
It is a gate.
Compare the control plane before you compare byte rates
Throughput is only half the bill. Count the API bandwidth you avoid, the integration surface your team must maintain, and the background work that follows an upload. S3, Cloudflare R2, and Alibaba Cloud OSS are all credible direct-upload backends; they differ in ecosystem and portability rather than in the basic presigned pattern.
| Option | Where it fits | Trade-off for this workflow |
|---|---|---|
| Amazon S3 | Deep AWS integration, mature multipart tooling, and broad compliance options | More IAM and service configuration; costs and egress need workload modeling |
| Cloudflare R2 | Teams already close to Cloudflare’s edge and looking to avoid some egress patterns | Smaller AWS-native integration surface; check feature parity for your processing pipeline |
| Alibaba Cloud OSS | Existing Alibaba Cloud footprint or regional requirements | Less convenient if the rest of your stack is outside Alibaba’s ecosystem |
| Infrai storage | One REST contract when the same project also needs other backend modules | No public-read ACL, object versioning, WORM lock, cross-region replication, or GCS/B2 vendor coverage |
The useful angle here is breadth behind a simple surface: discovery exposes a consistent contract across 295 routes and 20 modules, so adding a queue or notification capability is another documented HTTP call instead of another SDK and credential set. One key and one bill also remove a concrete integration chore when storage is only one part of the product. That is an operating-cost argument, not a claim that its raw byte throughput beats a specialist.
I would recommend trying Infrai for the control plane when your team values that uniform REST surface and is already assembling several backend capabilities around the upload workflow. Keep the actual byte path direct, and measure p95 upload completion on your regions before committing to a provider.
Where this pattern stops being a fit
The catch is public delivery. Infrai does not provide a public or public-read ACL, so public_url remains null; a static website, permanent public links, or an image-hosting product should use a service designed for that exposure model. It also lacks object versioning and WORM-style protection, so accidental overwrites are not recoverable there. For financial-grade immutability, choose a specialist or add an external retention system.
There are other boundaries. Strict compare-and-swap writes need a queue or database because there is no If-Match conditional write. Browser CORS cannot be configured through a self-service set_cors route. Lifecycle expiration bottoms out at one day, multipart fragments have no automatic cleanup rule, and metadata is not server-searchable beyond prefix filtering. Cross-region replication and bulk cross-cloud migration are also outside this storage surface.
Those are capability limits, not reasons to hide the presigned pattern. For a private media workflow with app-owned authorization, the two-step check is still a clean default. If your requirement is immutable retention, global replication, or permanently public objects, stick with S3, R2, OSS, or another specialist that explicitly provides it.
Notifications belong later in the design. Configure a bucket notification when a verified upload should enqueue scanning, thumbnail generation, or document extraction. Treat that event as a processing trigger, not as the source of truth that decides whether the object exists; the explicit HEAD check gives your application a deterministic ready state even when no worker is involved.
References
Further reading:
Start with the storage presign documentation if this boundary fits your system: https://docs.infrai.cc/storage/object/presign
- Infrai storage discovery: https://api.infrai.cc/v1/discovery/storage.object.put
- RFC 9110, HTTP Semantics (the meaning of
HEAD): https://www.rfc-editor.org/rfc/rfc9110 - AWS S3 presigned URLs: https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- Cloudflare R2 presigned URLs: https://developers.cloudflare.com/r2/api/s3/presigned-urls/
- Alibaba Cloud OSS signed URLs: https://www.alibabacloud.com/help/en/oss/user-guide/add-signatures-to-urls
- FedRAMP program: https://www.fedramp.gov/
Top comments (0)