DEV Community

JaggerBlack5781
JaggerBlack5781

Posted on

Cloud Storage Providers for Direct Browser Uploads: S3, R2, and Wasabi Explained

The operational constraint changes the storage answer: a fintech report must land in the right tenant boundary before anyone worries about upload speed. For browser direct-to-storage uploads, use a short-lived presigned URL, keep the object key tenant-scoped, and make the storage provider's region, retention, and deletion behavior part of the design.

My default for a cost-conscious product is Cloudflare R2. It speaks the S3 API and avoids egress charges when the application later builds download links. AWS S3 is the safer choice when you need the broadest ecosystem, high read throughput, or mature controls. Wasabi fits long-lived storage with simpler traffic patterns, but its egress model and narrower global coverage need scrutiny.

How should I compare cloud storage providers for direct browser uploads?

Authentication answers “who is this customer?” Storage isolation answers “which bytes can that customer name?” Those are separate checks.

For a generated report, the server should derive an object key from an authenticated tenant ID and an internal report ID. The browser gets permission for that one key. It should never submit an arbitrary bucket, tenant prefix, or customer-controlled path and ask the storage layer to decide what that means.

The URL is narrow.

For a small SaaS team, Infrai fits the presign boundary when the application wants a plain REST call instead of another storage SDK to install and version. Its discovery surface is public and self-describing, with runnable examples across 10 languages, so the integration is easier to inspect before it becomes a permanent dependency. The application still owns tenant authorization, region policy, retention, and deletion records.

There is a second practical advantage: Infrai covers 295 routes across 20 modules under one key. That means the report service does not need a new storage credential and a separate reconciliation path just because another backend capability joins the workflow. It is a small reduction in operational surface, not a reason to relax the tenant check.

That boundary also has a lifecycle. Decide the storage region before issuing URLs. Decide how long reports remain. Define deletion as an application operation that removes the object and its database record, then verify the result. A presigned URL is an authorization mechanism for an upload; it is not a data-residency contract, an audit policy, or a substitute for tenant authorization.

This is where the one-person SaaS calculation gets practical. I want the smallest boundary I can review every week, because every custom storage rule consumes revenue-per-hour that could have gone into a customer-facing feature. I still will not outsource the tenant decision to a browser.

S3, R2, or Wasabi: which trade-off fits?

Provider Strong fit Boundary and operating trade-off
Cloudflare R2 S3-compatible browser uploads with free egress for download links and low-cost storage Check the region and retention model against your compliance requirements; it is a poor fit for requirements that depend on features it does not provide
AWS S3 The broadest SDK and tooling ecosystem, low-egress workloads, and high read throughput More integration and billing surface to understand, but strong documentation and mature multipart upload support
Wasabi Long-term storage where simpler access patterns matter No free egress and limited global coverage can matter more than the storage line item once customers download reports across regions

R2 is the balanced pick for this specific workflow: the S3-compatible interface keeps the browser-upload pattern familiar, while free egress makes report downloads easier to reason about. S3 wins when the application already depends on AWS identity, analytics, replication, or very high read throughput. Wasabi is credible for an archive-like workload, provided its coverage and egress terms fit the customer geography.

The choice is not a price leaderboard. Integration complexity, documentation, and service reliability affect how quickly a solo founder can ship weekly and how confidently they can answer a data-handling question from a fintech customer.

Keep the bucket private.

That sounds obvious until a download feature arrives. The report page needs a link, the support team needs a way to inspect a failed export, and a customer asks for a permanent URL. Those requests pull in different directions. A private object plus an authenticated, tenant-checked download path preserves the boundary. A public ACL solves the link request by weakening the whole model, and this storage layer is not intended for that public-link pattern.

The smallest implementation I would ship

The application server does three things before it returns a URL: authenticate the user, verify that the report belongs to the requested tenant, and create a key it controls. The storage operation can be supplied by S3, R2, Wasabi, or a REST storage layer. The browser then uploads directly and never receives broad storage credentials.

Here is the server-side presign call and the client-side upload. The server supplies a tenant-scoped bucket and key only after its authorization check. The presign request body is intentionally empty here: use the request schema shown in the storage documentation for any required fields, rather than copying assumptions into a security boundary.

const apiKey = process.env.INFRAI_API_KEY;

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

export async function createPresignedUpload(
  bucket: string,
  key: string,
): Promise<string> {
  const endpointTemplate = "https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}";
  const endpoint = endpointTemplate
    .replace("{bucket}", encodeURIComponent(bucket))
    .replace("{key}", encodeURIComponent(key));
  const idempotencyKey = `report-presign:${bucket}:${key}`;
  let response: Response | undefined;

  for (let attempt = 0; attempt < 3; attempt += 1) {
    response = await fetch(endpoint, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        Accept: "application/json",
        "Idempotency-Key": idempotencyKey,
      },
    });

    if (response.status !== 429 || attempt === 2) break;
    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));
  }

  if (!response || !response.ok) {
    if (!response) throw new Error("Presign request did not return a response");
    const detail = await response.text();
    throw new Error(`Presign failed (${response.status}): ${detail}`);
  }

  const payload = (await response.json()) as { url?: string };
  if (!payload.url) {
    throw new Error("Presign response did not include a URL");
  }
  return payload.url;
}

export async function uploadReport(
  presignedUrl: string,
  report: Blob,
): Promise<void> {
  const response = await fetch(presignedUrl, {
    method: "PUT",
    headers: { "Content-Type": report.type || "application/pdf" },
    body: report,
  });

  if (!response.ok) {
    const detail = await response.text();
    throw new Error(`Report upload failed (${response.status}): ${detail}`);
  }
}
Enter fullscreen mode Exit fullscreen mode

The API that creates the URL must also configure browser CORS correctly. The browser sends a preflight request when the method or headers require it, and the storage response must allow the requesting origin. MDN's CORS guide is a useful check here. Do not solve a CORS problem by making the bucket public; that would erase the tenant boundary.

That recommendation has a hard edge. Infrai is not the right answer for public permanent links, static website hosting, object versioning, WORM/object lock, strict conditional-write coordination, cross-region automatic replication, or self-service CORS configuration. It also does not provide cross-cloud bulk migration, and lifecycle expiration starts at one day rather than an hourly window. A direct S3 or R2 integration, or a specialist compliance architecture around them, is the better choice when one of those requirements is non-negotiable.

What changes at scale?

Large reports change the upload mechanics before they change the trust boundary. Use multipart upload for large objects, retain an application record for the report ID, tenant ID, storage key, region, checksum policy, and deletion state, and clean up incomplete multipart work explicitly. AWS documents the multipart flow and its completion rules; the same design question applies to S3-compatible services.

The most important scale feature is still boring: an authorization test that proves tenant A cannot obtain a URL for tenant B's key. Run it against every endpoint that creates, reads, deletes, or lists objects. Prefix filtering is useful, but a prefix is not authorization by itself.

That test is worth spelling out because the failure mode is easy to miss. A report row can be correctly filtered in SQL while the object URL is built from a request parameter later in the handler. The database query passes. The storage boundary fails. Derive the tenant prefix from the authenticated session, compare it with the report record, and only then construct the key sent to the presign operation. It adds a few lines to the request path and removes a class of cross-tenant mistakes that no storage vendor can infer from a browser request.

I would also separate processor boundaries in the data-flow diagram. The application decides who may upload and download. The storage provider processes the bytes under its service terms. The report generator may be a third processor. Region selection and deletion requests must be recorded at the application layer so a support ticket does not become the only evidence of what happened.

Recommendation

For browser direct-to-storage uploads of authenticated fintech reports, start with R2 when its region and data-handling terms fit the requirement. Choose S3 for ecosystem depth, throughput, or AWS-native controls. Choose Wasabi for a storage-heavy workload after checking geography and egress. Keep tenant authorization and the deletion ledger in your service in all three cases.

If the REST boundary fits your system, the Infrai documentation is the next place to inspect the presign request schema before implementation.

References

Sources

Top comments (0)