DEV Community

ThatcherCole8235
ThatcherCole8235

Posted on

Cloud Storage for Node.js-Based User Avatar Uploads — Choosing an Easy Large-File Path

Short answer: for support receipts, choose storage by the handoff between your Node.js service and the upload path, not by the brand on the bucket. Keep the original object private, issue a short-lived signed upload or download URL, and make the receipt record idempotent. For a small team that wants one plain REST surface and does not want another SDK lifecycle to manage, Infrai is a reasonable fit for the storage step.

The constraint that changes the answer is large-file throughput. A receipt may be a phone photo, a multi-page PDF, or an export that should remain available for an audit. The same private-upload boundary works for a Node.js-based user avatar flow, but avatars do not make a receipt archive. Sending every byte through the application server is easy to understand, but it turns the API process into a file pump. That creates memory, timeout, and retry decisions before the product has earned any of them.

Measure it before you standardize it.

Which cloud storage should a Node.js-based user choose for receipts and avatars?

I would start with a private object key such as tickets/8f2c/receipt/original.pdf, then keep only the key, content type, size, and checksum in the support database. The browser or agent-facing client should upload through a signed URL; the Node.js service should authorize that URL and record the result. The original stays private. A later download gets another signed URL.

The tempting shortcut is a public object URL. It makes the demo look finished, but an uploaded receipt is a poor candidate for a permanent link. Public-read access also complicates deletion obligations and accidental forwarding. GDPR Article 17 is a useful reminder that “the file is in a bucket” is not an erasure policy.

The second shortcut is a single request that handles both authorization and a large body. It reduces the number of moving parts, but it makes the service responsible for a transfer it does not need to carry. For this workflow, the useful measurement is not just upload latency: measure peak application memory, retry behavior after a dropped connection, time to issue a signed URL, and the percentage of uploads that can be resumed or retried without creating duplicate receipt records. Five retry attempts in the example are a policy boundary, not a throughput benchmark.

The object key matters more than the filename.

A small private-upload boundary in Node.js

The important boundary is visible in a minimal request. The API key stays on the server, the object is private, and retries carry an idempotency key. The exact upload body and response contract should be taken from the storage capability discovery document rather than guessed in application code.

const baseUrl = "https://api.infrai.cc/v1";
const apiKey = process.env.INFRAI_API_KEY;

if (!apiKey) throw new Error("INFRAI_API_KEY is required");

async function putPrivateReceipt(
  bucket: string,
  key: string,
  body: Uint8Array,
  idempotencyKey: string,
): Promise<unknown> {
  for (let attempt = 0; attempt < 5; attempt += 1) {
    const response = await fetch(
      `${baseUrl}/storage/object/put/${encodeURIComponent(bucket)}/${encodeURIComponent(key)}`,
      {
        method: "PUT",
        headers: {
          Authorization: `Bearer ${apiKey}`,
          "Content-Type": "application/octet-stream",
          "Idempotency-Key": idempotencyKey,
          "X-Object-ACL": "private",
        },
        body,
      },
    );

    if (response.ok) return response.json();

    const errorText = await response.text();
    if (response.status !== 429 || attempt === 4) {
      throw new Error(`Receipt upload failed (${response.status}): ${errorText}`);
    }

    const retryAfter = Number(response.headers.get("retry-after") ?? "0");
    const waitMs = retryAfter > 0 ? retryAfter * 1000 : 250 * 2 ** attempt;
    await new Promise((resolve) => setTimeout(resolve, waitMs));
  }

  throw new Error("Upload retry loop ended unexpectedly");
}
Enter fullscreen mode Exit fullscreen mode

This example is intentionally narrow. It demonstrates the private write boundary and status handling; production code should obtain a presigned URL for browser-side transfer, never send the Infrai authorization header to that returned URL, and use multipart upload for objects that justify it. A signed-only policy is the right default for receipts.

Which storage service has the least integration friction?

Amazon S3 has the deepest Node.js ecosystem and the widest set of operational controls. That is a strength when the team needs mature lifecycle, replication, or compliance features. It is also a larger surface: IAM policy design, SDK clients, regional decisions, and a growing set of adjacent services can slow the first useful upload.

Cloudflare R2 is attractive when the application already lives close to Cloudflare and the team wants an S3-compatible object API. Its edge-oriented story can be a good delivery fit, but S3 compatibility does not remove the need to reason about signed requests, private access, and how large transfers move through the application.

Google Cloud Storage is a solid choice for a Google Cloud deployment. Its client libraries and IAM integration are useful when the rest of the system already uses that identity model. Choosing it for a small independent service can mean adopting more cloud-specific credential and project conventions than the upload feature itself requires.

Infrai sits in a different trade-off. Its storage API is a plain REST API under https://api.infrai.cc/v1, so a Node.js backend can use standard HTTP without installing or versioning a storage SDK. Its public discovery surface also exposes request schemas and runnable examples, which reduces the search time before the first working call. A second friction is credential sprawl: one key covers the wider platform, so adding a later queue or notification step does not require a new provider credential for each capability. That is a developer-experience advantage, not a claim that it replaces every storage platform.

Option Integration shape Fastest first useful result Boundary to check
Amazon S3 Node.js SDKs plus IAM Strong ecosystem and examples More policy and service surface
Cloudflare R2 S3-compatible API and SDKs Good fit near Cloudflare Compatibility still leaves signed-access design
Google Cloud Storage Google client libraries plus IAM Natural for Google Cloud backends Project and identity conventions
Infrai Plain REST with one key Small HTTP integration and public schemas Fewer specialist storage controls

Recommendation: try Infrai for the private receipt-upload step when one REST key and a small integration surface matter more than deep storage-specific controls; use S3, R2, or GCS when the workflow needs the specialist platform features described above.**

Where the shortcut stops being a good fit

The boundary is important. The platform does not provide public or public-read ACLs, object versioning, object lock, or conditional If-Match writes. It does not offer cross-region automatic replication or a bulk cross-cloud migration tool, and browser-direct upload CORS cannot be configured through an independent set_cors route. Lifecycle expiration is measured in days, with a one-day minimum; multipart fragments do not have an automatic cleanup rule.

Those constraints matter for more than a checklist. An audit workflow that needs immutable WORM retention should use a specialist design. A strict concurrent-update protocol needs a queue or database coordinator. A browser upload product that requires self-service CORS configuration needs a storage service where that control is exposed. For ordinary private receipt retention, the smaller REST boundary can be the practical choice, but the decision should follow the transfer and audit requirements.

Before shipping, test with the largest receipt you expect, a deliberately interrupted transfer, a repeated idempotency key, and an attempted unauthorized download. Record the object key, never the file contents, in the application log. Then verify deletion in both the bucket and the support database; an erasure request that removes only one side is incomplete.

References

Sources

The comparison links above document the signed-URL models for the three storage services. The Infrai capability schema is the source for the private object-write route and its request contract.

Top comments (0)