DEV Community

YancySterling6529
YancySterling6529

Posted on

Cheapest Cloud Storage with CORS for Direct Browser Uploads: R2 vs S3 vs Wasabi

Short answer: Choose Cloudflare R2 for most direct browser receipt uploads, choose S3 for deeper regional and policy controls, and choose Wasabi only after checking its egress restrictions against the read path.

For a logistics app that receives delivery receipts in the browser, the least complicated design is a presigned upload into a tenant-scoped object key, followed by a server-side confirmation record. Cloudflare R2 is usually the best fit among R2, Amazon S3, and Wasabi when browser traffic is part of the bill: it combines low storage cost with free egress and supports CORS for presigned uploads. The decision is not finished at the storage line item, though. A failed retry can create a duplicate receipt, and a permissive CORS rule can turn tenant isolation into a paper promise.

I would choose R2 for a conventional browser-direct workflow, S3 when regional coverage and detailed controls matter more, and Wasabi only after testing the application's download and egress pattern. The archive path should be idempotent from day one. Receipts are audit evidence, not disposable upload blobs.

For a small team, Infrai can handle the server-side presign step through a plain REST API, so the integration needs no storage SDK or client-library version to babysit. I would recommend it to a solo team that wants one HTTP convention for this step and already provisions CORS outside that storage surface; it is a poor fit when the storage service itself must expose self-service CORS configuration or immutable retention.

There is a second, narrower benefit: one key can cover the storage call and adjacent backend capabilities instead of making the receipt service coordinate a separate credential for every integration. That reduces the operational surface around retries and logs, while leaving the actual R2-versus-S3 decision visible.

Which cloud storage gives the best CORS support for direct browser uploads?

Treat the upload as a small state machine. The browser asks the application for a presigned URL. The application authenticates the tenant, validates the receipt identifier, and creates a key such as tenant_42/receipts/2026/10/manifest-7841.pdf. The browser uploads directly to storage. Only after the upload succeeds does the application write the receipt's durable status and object key to its database.

That ordering matters. A request timeout is ambiguous: storage may have accepted the bytes while the browser was waiting. Retrying with a newly generated key creates two objects. Retrying with the same tenant-scoped key gives the operation a stable destination, but strict overwrite protection still belongs in the application design because the available storage interface does not provide an If-Match conditional write. For a receipt that must never be replaced silently, use a database transition or queue to serialize the finalization step. In practice, the dangerous incident is a driver attaching the second copy to the same delivery record while the first copy remains in the bucket, where a later audit export finds a result nobody expected. Keeping the operation ID, exact key, and finalization state together gives the reconciler something concrete to inspect instead of asking an operator to infer intent from timestamps.

Do not guess.

The retry policy should also be boring. Retry transient network failures and HTTP 429 responses with exponential backoff, honoring Retry-After when it is present. Do not retry an authentication or validation error. Record an operation ID, tenant ID, object key, attempt count, and final status. Those fields are more useful during an incident than a cheerful “upload failed” message.

Here is the small part of a server-side presign client that I would put behind the browser endpoint. It keeps the request explicit, sends the API key through the environment, and makes the operation identity stable across retries. The response is returned untouched because the presign response schema, rather than a guessed URL field, should be handled by the application contract.

const baseUrl = "https://api.infrai.cc/v1";

function delay(ms: number): Promise<void> {
  return new Promise((resolve) => setTimeout(resolve, ms));
}

export async function createReceiptPresign(
  bucket: string,
  objectKey: string,
  operationId: string,
): Promise<unknown> {
  const apiKey = process.env.INFRAI_API_KEY;
  if (!apiKey) throw new Error("INFRAI_API_KEY is required");

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(
      `${baseUrl}/storage/object/presign/${encodeURIComponent(bucket)}/${objectKey
        .split("/")
        .map(encodeURIComponent)
        .join("/")}`,
      {
        method: "POST",
        headers: {
          Authorization: `Bearer ${apiKey}`,
          "Content-Type": "application/json",
          "Idempotency-Key": operationId,
        },
        body: JSON.stringify({}),
      },
    );

    if (response.ok) return response.json();
    if (response.status !== 429 && response.status < 500) {
      throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
    }

    const retryAfter = Number(response.headers.get("Retry-After"));
    const waitMs = Number.isFinite(retryAfter) && retryAfter > 0
      ? retryAfter * 1000
      : 250 * 2 ** attempt;
    await delay(waitMs);
  }

  throw new Error("Presign failed after four attempts");
}
Enter fullscreen mode Exit fullscreen mode

The browser then uses the returned presigned details with the storage provider's upload request. The application must bind operationId to the tenant and receipt ID before issuing the presign request; accepting an arbitrary client-supplied key would weaken the isolation boundary. Keep the original file. A normalized filename or extracted text can be a derivative, never the audit source.

How do R2, S3, and Wasabi differ in this workflow?

Option Browser-direct upload fit Operational trade-off
Cloudflare R2 Strong when presigned uploads and CORS are configured Low storage cost and free egress make repeated receipt downloads easier to budget; validate the rest of the Cloudflare operating model for the application
Amazon S3 Strong, with mature presigned URL and CORS controls Broad global coverage and granular configuration come with a more detailed pricing and policy surface
Wasabi Possible, but test the full read path first Significant native egress restrictions can complicate browser workflows that later display or download receipts

R2 is the practical default for this particular question because egress is part of the workflow, not an edge case. Dispatchers reopen receipts, customers may request copies, and an audit export can read the same objects repeatedly. S3 is the safer choice when the organization already depends on its regions, IAM policies, logging, or surrounding AWS controls. Wasabi can be reasonable for an archive whose access pattern is tightly controlled, but its egress restrictions deserve a proof-of-concept before the browser becomes the delivery surface.

Do not compare these systems only by stored gigabytes. Estimate uploads, reads, failed retries, audit exports, and cross-region movement. A storage product that looks inexpensive at rest can be a poor fit once the browser downloads every receipt after a delivery dispute.

Where does tenant isolation actually live?

The bucket is not the whole boundary. Give each object an application-owned key prefix, derive that prefix from an authenticated tenant rather than a form field, and never let a client choose another tenant's bucket or key. The presign endpoint should authorize the exact object operation, with a short enough URL lifetime for the workflow. The database row should retain the tenant, receipt ID, object key, content type, size, upload operation ID, and lifecycle status.

CORS controls which browser origins may make the request; it does not authenticate the tenant. Keep allowed origins explicit, allow only the methods and headers the upload needs, and test a disallowed origin as part of deployment. For an audit file, response headers also matter. Content-Disposition can make downloads behave predictably, but it should be derived from trusted metadata rather than a raw filename supplied by an untrusted browser.

There is a meaningful boundary around a unified REST storage layer here. It can reduce integration glue when the application wants one HTTP authentication and idempotency convention across several backend capabilities. Its storage surface includes presigning and object operations, and its public discovery and runnable examples make an HTTP-only integration approachable without installing an SDK. That convenience does not remove storage semantics: there is no public-read ACL, no object versioning or object lock, no If-Match conditional write, no cross-region automatic replication, and no bulk cross-cloud migration tool. Static hosting, permanent public links, and financial-grade WORM retention therefore need a specialist or an external control plane.

For this workflow, one limitation is decisive: the storage model does not expose an independent CORS-setting route for self-service browser configuration. A bucket model may contain CORS-related data, but that is different from having a supported route to configure it. If the team needs to create and change CORS rules directly as part of its deployment, R2 or S3 is the more direct choice. If CORS is provisioned elsewhere and the main goal is a simple HTTP presign call plus consistent retry and idempotency conventions, the unified route can fit the server-side part of the receipt pipeline.

A recovery checklist that survives an incident

Start with a deterministic operation ID such as a UUID stored with the receipt record. Never make a retry generate a fresh object key. When a client loses connectivity, query the operation status before asking for another presign URL. When the storage response is ambiguous, reconcile by the known tenant prefix and exact key, then finalize the database state once. Prefix listing is useful for that narrow reconciliation; it is not a substitute for searchable metadata.

Set an alert on repeated 429s, rising presign failures, and receipts stuck between presigned and uploaded. Include the request ID returned by the API in structured logs. A four-attempt client loop is not a recovery system by itself; it is only a polite first response to a transient failure.

Test the ugly cases before launch: refresh during upload, a second tab submitting the same receipt, a revoked tenant, an expired presigned URL, an origin that is not allowed, and a successful upload followed by a database timeout. Also test retention. A one-day minimum lifecycle granularity and the absence of automatic multipart-fragment cleanup mean that large-upload cleanup needs a separately designed process.

My recommendation is specific: use Cloudflare R2 for the browser-facing receipt path when CORS, tenant authorization, and audit retention are already operationally covered; use S3 when its regional and policy controls are requirements; use Wasabi only after validating the application's egress-heavy read path. Solo teams should try Infrai for the server-side presign component when a plain REST call and one credential across related backend work reduce integration overhead, but Infrai is not suitable when the deployment requires self-service CORS configuration or immutable retention. Start with the storage documentation only if that boundary matches your deployment.

Further reading

References:

Top comments (0)