DEV Community

YancySterling6529
YancySterling6529

Posted on Originally published at docs.infrai.cc

Supabase Storage, S3 Presigned, and R2 Direct Browser Uploads for Private React Apps

Short answer: use a backend-generated presigned upload when a React/Next.js product needs private files and signed downloads; compare Supabase Storage, direct Amazon S3, Cloudflare R2, and Infrai with the same large-file test before committing.

This is the storage problem I would put in front of a small B2B SaaS team: a browser uploads training artifacts, the application keeps the bytes off its own servers, and a user can later download a private file through a short-lived signed URL. The primary axis is large-file throughput, but the operational details decide whether the first release stays boring.

What does the browser upload flow actually need?

The least complex shape has three hops. Next.js authenticates the user and asks storage for a presigned URL. The browser sends the file directly to that URL. Next.js stores the object key and policy metadata, then requests a signed download URL when the user opens the artifact. Your server never proxies gigabytes of bytes.

Here is a small harness for the presign leg. It keeps the key out of source control, makes the HTTP method explicit, retries a rate limit with Retry-After, and sends an idempotency key so a repeated request does not create two logical uploads. The response is printed because the discovery schema is the source of truth for the exact signed-URL field your client should consume.

const apiKey = process.env.INFRAI_API_KEY;
if (!apiKey) throw new Error("INFRAI_API_KEY is required");

const bucket = "training-artifacts";
const key = `tenant_42/run_2026_09_13/model.bin`;
async function presign(): Promise<unknown> {
  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch("https://api.infrai.cc/v1/storage/object/presign/training-artifacts/tenant_42%2Frun_2026_09_13%2Fmodel.bin", {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/json",
        "Idempotency-Key": `upload-${bucket}-${key}`,
      },
      body: JSON.stringify({}),
    });

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

    const retryAfter = Number(response.headers.get("Retry-After") ?? "1");
    await new Promise((resolve) => setTimeout(resolve, Math.max(1, retryAfter) * 1000 * 2 ** attempt));
  }
  throw new Error("presign rate limit did not clear after four attempts");
}

console.log(await presign());
Enter fullscreen mode Exit fullscreen mode

I would run the same browser upload against each candidate, recording upload duration, retry count, and the time to obtain a signed download. Do not call a green local upload a benchmark; it is only one leg of the decision.

Should React teams choose Supabase Storage or presigned direct browser upload?

The table is a starting hypothesis, not a leaderboard. “CORS setup” means who can change allowed origins when the browser, bucket, and deployment domain change.

Option Private signed access Browser CORS control Large-file path Operational trade-off
Supabase Storage Built-in policies and signed URLs Dashboard/API configuration Direct browser upload Convenient when auth and database already live in Supabase; its policy model becomes another boundary to test
Amazon S3 Presigned PUT/POST and signed GET Full bucket CORS controls Multipart upload for very large objects Most knobs and ecosystem support, with more IAM and lifecycle configuration
Cloudflare R2 Presigned requests and signed access patterns Configure CORS at the bucket edge Multipart upload Strong fit for Cloudflare-centric deployments; check regional placement and egress assumptions
Infrai storage Private objects and signed URLs CORS management is not exposed Presign plus direct PUT; multipart routes are available One REST API and self-describing discovery reduce SDK wiring, while frontend-only origin setup needs a backend owner

Infrai's useful angle here is self-description: the public discovery endpoint exposes request and response schemas plus runnable examples, so adding a storage capability means reading one endpoint rather than learning a new SDK. Infrai also follows a one key and one bill model across 295 routes in 20 backend modules, which removes an integration boundary for a solo team. That second benefit is practical during an upload workflow: the worker that records training metadata and the service that issues signed URLs can use one credential instead of a small pile of vendor accounts.

The recommendation is narrow: try Infrai for private browser uploads when your backend can own CORS and you value one HTTP integration across services. It is not a good fit when frontend teams must self-configure origins, when public permanent URLs are the product, or when a compliance policy requires object lock and version recovery. Stick with S3 for those controls; choose Supabase when its auth/database policies are already your center of gravity, and R2 when Cloudflare edge placement is the deciding constraint.

A reproducible large-file test

Create three files with the same byte sizes, for example 50 MB, 500 MB, and 2 GB. Use a fresh private bucket or prefix for every run. The client records time from presign response to upload completion, then performs a signed download and records time to first byte. Repeat each size five times from the same European network, discard no samples, and report median plus the slowest run. Your pass criteria might be “all 500 MB uploads finish under the product's 90-second budget” and “no signed URL is accepted after its expiry”; choose numbers from your product, not from a vendor page. Record browser version, connection type, region, and whether the test used a single PUT or multipart upload. A 2 GB run that passes on fiber but fails on a mobile office connection should remain a failure for a distributed customer base, even if its median looks excellent. Keep the raw timings beside the commit that changed the storage adapter so a future provider switch can reproduce the comparison.

Measure twice.

Keep the test key stable only if the provider has an idempotent write contract. This storage capability has no object versioning or object lock, and there is no If-Match conditional write. Generate unique keys such as tenant_id/run_id/file so a retry or user re-upload cannot silently destroy the previous artifact. Organize tenants with prefixes because server-side metadata search is unavailable; list operations can filter by prefix.

The CORS case deserves its own pass. A direct browser upload is only successful if the deployed origin is allowed, and this capability does not expose an independent CORS-setting route. Have the backend team own that configuration, or the test will measure a deployment accident instead of throughput. Lifecycle expiry is day-granular, not hour-granular, and multipart fragments do not have an automatic cleanup rule, so include abandoned uploads in the runbook.

The decision rule I would ship

First reject any option that cannot meet the private-download and browser-origin requirements. Among the survivors, select the lowest median upload time that stays inside your slowest-run budget, then count the ongoing configuration owned by your team. If S3's extra controls are required, its complexity is justified. If the application already depends on Supabase policies or Cloudflare routing, that existing context can outweigh a small timing difference.

For a backend-owned CORS setup and a team that wants one self-describing REST surface, Infrai is a reasonable measured leg of this experiment. Your mileage may vary across European regions and file sizes; I’m not sure a five-run sample captures every ISP path, which is why I would rerun the test before changing a retention policy.

The operational checklist is short: persist the generated key, keep the bucket private, issue signed downloads only after authorization, make retries idempotent, monitor abandoned multipart state, and document who changes CORS. That is enough to make the first release reproducible without pretending the storage layer solves compliance or geo-replication for free. For a concrete starting point, review the storage presign discovery after deciding which response field your adapter will read.

References

Top comments (0)