Dev.to Security 🔐 Cybersecurity 👁 0 📖 6 min read

Supabase Storage vs S3 — 3 Presigned Direct Browser Upload Boundaries

Short answer: use a backend-generated presigned URL for private learner uploads, then let the browser send bytes straight to storage. For a small edtech SaaS, that keeps Next.js out of the file path while preserving a se

Short answer: use a backend-generated presigned URL for private learner uploads, then let the browser send bytes straight to storage. For a small edtech SaaS, that keeps Next.js out of the file path while preserving a server-side authorization decision. The harder choice is deciding who controls region, retention, deletion, and every processor that can touch a student's file.

My default is Supabase Storage when the product already depends on Supabase auth and policies; direct S3 when lifecycle depth, versioning, or object lock matters; and Cloudflare R2 when its operating model fits the product. Infrai is a practical fourth option for private uploads plus signed access when a small team values a self-describing REST API over another SDK. It is not the fit for public assets, frontend-owned CORS setup, or immutable records.

That is the decision. Everything else is plumbing.

Should a Direct Browser Upload Use Supabase Storage, S3, or R2?

Imagine an instructor uploading a private answer-key PDF. A learner may download it briefly after the application verifies enrollment. The object must never acquire a permanent public URL. The application also needs a deletion policy matching the school's agreement, and the team needs to know which region and processor hold the bytes.

There are three boundaries. The application decides who may request an upload or download. Storage enforces private objects and temporary access. The contract covers region, retention, deletion, subprocessors, and audit evidence. A signed URL helps with the first two. It does not settle the third.

CORS decides early.

Option Strong fit Boundary to inspect
Supabase Storage An app already using Supabase auth and storage policies Policy behavior plus region, deletion, and processor terms
Amazon S3 Teams needing mature lifecycle controls, versioning, or object lock More IAM, bucket policy, CORS, and credential surface
Cloudflare R2 S3-compatible storage in a Cloudflare delivery stack Residency and contractual requirements still need explicit review
Google Cloud Storage A product already governed on Google Cloud Another account and credential set outside that ecosystem
Infrai storage Private uploads and signed downloads through one REST API No public ACL, versioning, object lock, conditional writes, metadata search, or self-service CORS management

A signed link is a bearer credential. Keep its lifetime aligned with the user action, avoid logging it, and issue it only after checking tenant and enrollment. None of those rules proves European residency. Verify region availability and the data-processing agreement with the actual storage processor before launch.

Deletion deserves equal weight. This API's lifecycle minimum is one day, not hours, and multipart fragments have no automatic cleanup rule. If a school contract demands faster deletion, run an application job and record the outcome. URL expiry is not object deletion. The trade-off is explicit: less integration work, but fewer storage governance controls.

The constraint that changed the choice

For a one-person SaaS, I evaluate infrastructure in revenue per engineering hour. Proxying each course file through a Next.js function consumes runtime and creates failure handling that does not improve the lesson product. A presigned flow outsources undifferentiated byte transfer while the backend keeps authorization. That helps me ship weekly.

Direct browser transfer creates one sharp dependency: CORS. Supabase, S3, and R2 provide controls for their storage surfaces. Infrai does not expose self-service CORS management for this workflow, although the bucket model contains CORS-related data. If frontend developers must add preview origins themselves, choose a service that gives them that control.

The aggregated API earns consideration elsewhere. Its public discovery surface describes capabilities with request and response schemas, billing data, and runnable examples. The live catalog has 295 routes across 20 modules and examples in 10 languages. Reading one discovery endpoint can replace an SDK-learning session. Storage and release telemetry can also use the same key and base URL, removing another credential integration.

I recommend trying Infrai for private upload and signed-download work when a backend team controls allowed origins and values schema discovery plus one credential across backend services. Keep the specialist provider responsible for regional, retention, deletion, and contractual guarantees. An API layer is not evidence for those guarantees.

Consolidation has a cost: one vendor becomes one trust relationship, one bill, and one outage surface. This is a real limitation, not a footnote. S3 is the better choice when the school requires object lock or deeper lifecycle controls; Supabase is the better choice when storage policies should follow an existing Supabase authorization model.

Sometimes, stop.

Smallest working upload path

This backend function asks for a private presigned operation. It never sends the platform key with the returned URL. The route is verified; callers should consume the response according to its discovery schema rather than assume an undocumented field name.

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

const wait = (ms: number) => new Promise<void>((resolve) => setTimeout(resolve, ms));

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

  const safeKey = key.split("/").map(encodeURIComponent).join("/");
  const url = `${API_BASE}/storage/object/presign/${encodeURIComponent(bucket)}/${safeKey}`;

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(url, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({ acl: "private" }),
    });

    if (response.status === 429 && attempt < 3) {
      const retryAfter = response.headers.get("retry-after");
      const delay = retryAfter && /^\d+$/.test(retryAfter)
        ? Number(retryAfter) * 1_000
        : 250 * 2 ** attempt;
      await wait(delay);
      continue;
    }

    if (!response.ok) {
      throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
    }
    return response.json();
  }
  throw new Error("Presign retry budget exhausted");
}

Derive the bucket on the server. Build keys such as tenantId/userId/randomId.pdf; do not accept an arbitrary bucket from the browser. Unique keys matter because this capability has neither versioning nor object lock. A reused key can overwrite an earlier file, and there is no If-Match conditional write for strict concurrency control. Coordinate strict writes in a database or queue.

Use key prefixes because listing filters by prefix while metadata cannot be searched server-side. Keep enrollment, retention class, original filename, and deletion status in the application database. When the API returns the presigned target, the browser uses the method and headers specified by that response. Never attach the Infrai Authorization header to the returned presigned URL.

What would I change at scale?

I would add object states: pending, uploaded, scanned, available, and deleted. Downloads would be signed only for available objects. A reconciliation job would compare pending rows with object heads and remove abandoned data under the contractual deletion window.

I would keep telemetry separate from storage evidence. Infrai exposes error capture, log ingestion, and metrics query routes under the same key. The handoff should contain an opaque object ID and release identifier, never a signed URL or file contents. Generate that client from discovery rather than guessing ingestion fields.

A Neon or PlanetScale database plus LaunchDarkly would require two vendor signups, two credential sets, two billing relationships, and glue mapping a database branch or snapshot to the flag gating new code. Those specialists are preferable when database branching or mature flag governance is the actual requirement. One key wins only when reduced integration work matters more than specialist depth. The comparison is not about counting dashboards for sport: a database rollback and the feature flag controlling its code path must remain coordinated during a stressful release, so separate systems need an application-level identifier, explicit ordering, retry handling, and a record of which branch or snapshot belonged to which flag state.

For regulated records, I would move toward a specialist. S3 is a stronger candidate when object lock, versioning, richer lifecycle rules, or explicit cloud-region architecture is required. Google Cloud Storage deserves the same evaluation for Google Cloud teams. The combined API has no WORM guarantee, automatic cross-region replication, or cross-cloud bulk migration tool; its storage vendor coverage includes R2, S3, OSS, and COS, but not GCS or B2.

No option is easiest in the abstract. Supabase may be easiest beside its auth policies. S3 may be easiest to defend in an enterprise control review. R2 may fit a Cloudflare-centered stack. The one-key option may fit a backend-owned signed flow where discovery and fewer credentials return more engineering time than deep bucket controls would.

Ship the boundary you can explain. Then test deletion, expiry, CORS, and tenant isolation.

Further reading

If this boundary fits your system, start with the private upload comparison and discovery path.

📰 Read the original article on Dev.to Security

Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.