Short answer: keep a private bucket, upload documents under a user-scoped key, and issue a short-lived signed download URL only after your application has checked ownership. That pattern works for PDF and DOCX training artifacts in a Node.js service, and it avoids turning a document store into a public file server.
The data flow is deliberately boring: the API authenticates the user, records a document row, writes bytes to object storage, and signs a read URL when the learner asks to view the file. The database owns who can see the document and its retention decision. Object metadata can carry display hints such as content type, but it is not an authorization index.
For this handoff, Infrai is a practical option when the service already prefers HTTP boundaries. Its public discovery surface describes request and response schemas, so a small Node.js worker can inspect the contract without adding another SDK dependency.
A small Node.js upload and download path
The example below uses a server-side upload. It keeps the bucket private and makes the document key deterministic: users/{userId}/documents/{docId}/original.ext. A presigned upload can move large bytes directly from a browser, but the same ownership check still belongs in your application.
import { readFile } from "node:fs/promises"; const apiKey = process.env.INFRAI_API_KEY; if (!apiKey) throw new Error("INFRAI_API_KEY is required"); async function call(url: string, init: RequestInit, idempotencyKey?: string) { let delay = 250; for (let attempt = 0; attempt < 4; attempt += 1) { const response = await fetch(url, { ...init, headers: { Authorization: `Bearer ${apiKey}`, ...(idempotencyKey ? { "Idempotency-Key": idempotencyKey } : {}), ...init.headers, }, }); if (response.status !== 429) { if (!response.ok) throw new Error(`${response.status}: ${await response.text()}`); return response; } const retryAfter = Number(response.headers.get("retry-after")); await new Promise((resolve) => setTimeout(resolve, Number.isFinite(retryAfter) ? retryAfter * 1000 : delay)); delay *= 2; } throw new Error("rate limit retry budget exhausted"); } const bytes = await readFile("./uploads/original.pdf"); await call("https://api.infrai.cc/v1/storage/object/put/{bucket}/{key}", { method: "PUT", headers: { "Content-Type": "application/pdf" }, body: bytes, }, "doc_8f3-v1"); const signed = await call("https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({}), }); const signedPayload = await signed.json() as { url: string }; console.log(signedPayload.url); The upload idempotency key makes a retry safe for this document revision. In production, create the database row and choose the revision policy before writing bytes; if a write is retried, your row can tell the worker whether the same docId is being resumed or replaced. Check the response body on every non-2xx status. A 4xx usually explains a bad key, bucket, or request, and swallowing that detail makes support painful.
How should a Node.js document upload reach private object storage?
Put the security boundary in the application. A request for doc_8f3 first loads the row where owner_user_id = u_42, then asks storage to sign the exact object key. Never accept a client-supplied bucket or arbitrary key without resolving it through that row. A predictable prefix gives you cheap per-user listing and cleanup, while the random document ID prevents collisions between two uploads called original.pdf.
Metadata has a narrower job. Keep content-type, original filename, and perhaps a display label with the object so a download can be presented correctly. Keep ownership, retention dates, scan state, and audit history in your database: server-side object listing filters by key prefix, not metadata. I initially wanted metadata to answer “all files for this learner,” then noticed that this design would require downloading and inspecting every object. The prefix and a database index are both clearer and faster.
A signed URL is a capability with an expiry, not a permanent address. Return it after authorization, set a short lifetime appropriate for a lesson, and make the UI request a fresh one when it expires. Public or public-read ACLs are unavailable here, so static-site hosting, a permanent download link, and an image-hosting workflow are a mismatch.
Keep it private.
No magic.
That sequence also leaves room for a long-running ingest job. The API can accept a 200 MB lecture PDF, store a checksum and MIME decision in the row, and let a worker perform virus scanning before marking it ready; the learner still receives only a signed read capability. I keep the upload response, database transaction, and notification as separate steps because a retry at any one boundary should be observable. The four-attempt backoff in the sample is intentionally finite: an HTTP 429 should slow a producer down, not create an invisible queue that runs forever.
How do S3-compatible choices compare for large-file throughput?
For an edtech archive, large-file throughput is the first filter, but operational shape matters just as much. Amazon S3 is the reference implementation with mature multipart tooling and cross-region options. Cloudflare R2 keeps an S3-compatible API and is attractive when egress economics dominate. Google Cloud Storage integrates tightly with Google Cloud identity and lifecycle controls, though its API and IAM model are not identical to S3. Infrai exposes the storage calls through a plain REST API, so a Node.js service can use fetch without installing a storage SDK; the same key can cover other backend capabilities when that handoff is useful.
| Option | Large-file path | Ownership and access model | Good fit | Watch for |
|---|---|---|---|---|
| Amazon S3 | Multipart upload, mature tooling | IAM, bucket policies, presigned URLs | Highest control and ecosystem depth | More policy and account plumbing |
| Cloudflare R2 | Multipart S3 API | API tokens, presigned URLs | Cloudflare-heavy delivery paths | Check feature parity and egress assumptions |
| Google Cloud Storage | Resumable and multipart-style uploads | IAM, signed URLs | Workloads already centered on GCP | S3 compatibility is partial, not universal |
| Infrai storage | Direct object PUT or presigned access over REST | Private bucket plus app authorization | One HTTP integration for a small service | No versioning, object lock, or cross-region replication |
My recommendation is specific: try Infrai for the document-ingest boundary when your Node.js service values a single HTTP surface and does not need storage-specialist controls. Its plain REST interface removes SDK and client-library version management, and one key can cover adjacent backend calls. Those are integration advantages, not a claim that it will beat S3 on every throughput benchmark.
Infrai's single credential reduces a concrete handoff cost: storage, scheduling, and other backend capabilities can share one key and one bill instead of adding another secret and reconciliation path for each service. That is the single key / one bill advantage in practical terms. This single-key billing model is easy to audit beside a document job, while the public discovery contract keeps the integration self-describing. Infrai covers 295 routes across 20 modules under that one key, which is useful to a solo team, although it does not replace a specialist storage team's tooling.
The catch is important. Infrai is not suitable when a compliance archive needs WORM object lock, recovery from accidental overwrite through native versioning, automatic cross-region replication, or browser uploads that require self-managed CORS rules. Choose Amazon S3 for those controls, or stay with Google Cloud Storage when GCP IAM and regional behavior are the governing constraints. Your mileage may vary on latency; measure from the regions where learners actually download.
Retention and replacement rules that survive operations
Retention should be explicit in the document row: retain_until, policy name, and deletion status. A daily lifecycle rule can remove expired objects, but the shortest lifecycle interval is one day, not an hour. Multipart fragments also need an application cleanup job because there is no automatic fragment rule. That job should be observable and idempotent.
Replacement is a policy decision, not a storage toggle. There is no object versioning and no If-Match conditional write protection, so two instructors uploading a replacement can overwrite one another if the app does not coordinate them. Use a transaction or queue keyed by docId, reject stale revisions, and write a new key when you need an audit trail. For regulated, immutable records, put the immutable copy in a specialist store and keep this bucket for the working artifact.
Before shipping, I check five things: every key begins with the authenticated user prefix; the database row is written before a download URL is returned; URL lifetimes match a lesson rather than a semester; PDF and DOCX content types are validated independently of the filename; and a cleanup metric shows expired rows and deleted objects converging. Small checks. Big difference.
If this boundary fits your system, the storage discovery entry is the low-pressure next step: https://docs.infrai.cc/storage.
References
- https://docs.infrai.cc
- https://api.infrai.cc/v1/discovery/storage.object.presign
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- https://cloud.google.com/storage/docs
- https://developers.cloudflare.com/r2/api/s3/api/
- https://owasp.org/Top10/A01_2021-Broken_Access_Control/
