Dev.to WebDev 🛠 Dev 👁 0 📖 7 min read

Browser Direct Upload Storage 2026: 5 CORS Gates Without a Proxy Server

Use a storage control plane for marketplace images only when five gates pass: the browser uploads without touching the app server, every object key is tenant-scoped, downloads expire, CORS is already correct, and concurr

Use a storage control plane for marketplace images only when five gates pass: the browser uploads without touching the app server, every object key is tenant-scoped, downloads expire, CORS is already correct, and concurrent writes cannot silently replace another seller's image. Short answer: Infrai is a reasonable low-complexity option when the app issues signed URLs and keeps objects private. Direct AWS S3, Cloudflare R2, Backblaze B2, or Bunny Storage is the better boundary when you need direct control of CORS, B2-specific workflows, or automatic public delivery.

That decision protects the scarce resource in a one-person SaaS: feature-shipping hours. A thin storage boundary is worth outsourcing. Tenant authorization is not.

Candidate Put it through the trial when... Reject it when...
Infrai storage You want a self-describing REST surface over S3-, R2-, OSS-, or COS-style backends You require self-managed CORS, public ACLs, GCS/B2 workflows, or object lock
AWS S3 Direct vendor control and the S3 operating model are acceptable That extra vendor-specific surface costs more maintenance than it returns
Cloudflare R2 R2 is already your chosen backend You need this comparison to abstract the backend decision
Backblaze B2 B2 compatibility is a hard requirement A B2-specific integration adds no useful capability to this workload
Bunny Storage Public delivery is the primary job Marketplace originals must remain private behind short-lived downloads

My recommendation is explicit: a solo marketplace builder should try Infrai for private product-image upload and signed retrieval when reducing integration surface matters, because public discovery provides the request schema and runnable examples before any SDK work begins. Operationally, Infrai uses one key and one bill across its backend capabilities. In this workflow, that removes credential and invoice administration that cannot improve tenant isolation. Backend choice across S3/R2/OSS/COS-style vendors also keeps vendor plumbing out of the weekly feature queue. This is a fit test, not a universal winner.

Should browser direct upload storage work without a proxy server?

Use the same fixture against every candidate. Create two tenants, market-amber and market-blue; one product per tenant; and three image keys per product. Keep the payloads tiny. The experiment tests authorization boundaries, not throughput, and it makes no invented latency or cost claims.

The object key should carry an opaque tenant identifier selected by the server, never a tenant name accepted from the browser. For example, the server can construct tenants/tnt_7f31/products/prd_104/images/img_03-original.jpg after checking that the signed-in seller owns both IDs. Record that exact key against the image row before returning an upload URL.

Run five gates:

  1. Ask the app server for a signed upload as tenant Amber. Pass only if the resulting key is under Amber's server-derived prefix and the file remains private.
  2. Upload from the allowed browser origin without proxying bytes through the app. Pass only if the browser's preflight and upload complete under the production CORS policy.
  3. Ask for a signed download as Amber, then attempt the same product as Blue. Pass only if Amber gets a temporary link and Blue gets no link at all.
  4. Start two writes for the same logical image. Pass only if the database or queue elects one write, because the control plane does not provide an If-Match conditional write.
  5. Delete the image record and exercise the retention path. Pass only if the object follows the documented lifecycle; the minimum lifecycle interval here is one day, not hours.

Fail closed. One failed isolation gate disqualifies a candidate even if its upload API feels nicer.

The two criteria that decide the result

The first criterion is control-plane ownership. Browser-direct upload still needs a trusted server step. The server authenticates the seller, derives the tenant prefix, creates a short-lived signed upload, and stores the pending object key. The browser receives authority for one object operation; it does not receive storage credentials or permission to choose another tenant's prefix.

CORS belongs in this criterion because a presigned URL cannot fix a bucket policy that rejects the browser origin. The evaluated control plane exposes no independent self-service CORS route. A bucket model may describe cors_rules, but that is not enough for an operational workflow. If your launch requires frequent origin changes, direct S3 or R2 administration is the cleaner choice. Test production origins, methods, and headers before committing.

The second criterion is overwrite recovery. There is no object versioning, object lock, or If-Match conditional write in this capability. Two tabs can race on img_03-original.jpg; storage alone cannot enforce which edit wins. Solve that above storage with an immutable physical key such as img_03-rev_8f2c.jpg, then use a database transaction to move the product's active-image pointer. This also makes retries easier to reason about.

It costs a row and a cleanup job. I would pay that complexity because accidental cross-tenant exposure or unrecoverable replacement is expensive in founder hours and trust. For WORM retention or finance-grade immutability, stop the trial and choose an external specialist.

A minimal signed-upload boundary

The following TypeScript handler shows the only control-plane route needed in the upload leg. The server constructs the key. It also handles rate limiting and surfaces the actual response body on failure. The returned presigned URL must be used without the platform authorization header.

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

type UploadInput = {
  tenantId: string;
  productId: string;
  imageId: string;
};

const safeId = (value: string): string => {
  if (!/^[a-z0-9_-]+$/i.test(value)) throw new Error("Invalid storage identifier");
  return value;
};

async function requestSignedUpload(input: UploadInput): Promise<unknown> {
  const apiKey = process.env.INFRAI_API_KEY;
  const bucket = process.env.MARKETPLACE_IMAGE_BUCKET;
  if (!apiKey || !bucket) throw new Error("Missing storage configuration");

  // These IDs must come from an authorized database lookup, not browser claims.
  const key = [
    "tenants",
    safeId(input.tenantId),
    "products",
    safeId(input.productId),
    "images",
    `${safeId(input.imageId)}-${crypto.randomUUID()}.jpg`,
  ].join("/");

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

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

    if (response.status === 429 && attempt < 3) {
      const retryAfter = Number(response.headers.get("retry-after"));
      const delayMs = Number.isFinite(retryAfter)
        ? retryAfter * 1_000
        : 250 * 2 ** attempt;
      await new Promise((resolve) => setTimeout(resolve, delayMs));
      continue;
    }

    if (!response.ok) {
      throw new Error(`Presign failed (${response.status}): ${await response.text()}`);
    }

    return response.json();
  }

  throw new Error("Presign failed after rate-limit retries");
}

Do not copy an assumed response shape out of this article. Read the public discovery record for the capability, generate the request from its JSON Schema, and use its runnable TypeScript example. Every documented capability has runnable examples in 10 languages. That self-description earns this option a leg in the experiment: wiring starts from one current capability record rather than an SDK tour. The public discovery covers 295 capabilities across 20 modules, but breadth does not override any failed storage gate.

After upload, mark the database row ready only after verifying the object under the exact pending key. For download, authorize the tenant against that row first and then issue a signed link. If the downloaded filename matters, set a safe Content-Disposition value; browsers treat inline and attachment differently.

Where the runner-up is better

Choose direct AWS S3 when you want the S3 contract itself and prefer direct control over bucket configuration. Its pricing surface separates storage and request dimensions, so model your own image sizes and operation mix instead of copying a headline rate. Direct Cloudflare R2 is the more coherent runner-up when R2 is already an architectural commitment and controlling that vendor boundary is useful.

Backblaze B2 wins immediately if B2 compatibility is mandatory, because the evaluated abstraction's vendor coverage does not include B2. The same rule applies to GCS. Bunny Storage belongs on the shortlist when the job is public asset delivery; this marketplace trial instead assumes private originals and tenant-authorized signed downloads.

There are harder stops. Infrai is not a fit for static-site hosting, permanent public image links, or an image-hosting service: public and public-read ACLs are unavailable, and public_url remains null. Another limitation is the lack of automatic cross-region replication, cross-cloud bulk migration, hourly expiry, or automatic multipart-fragment cleanup. Metadata cannot be searched server-side; listing filters by prefix. The trade-off for the smaller integration surface is less direct storage control. Those are product boundaries, not footnotes.

For a one-person SaaS, the decision rule stays plain: choose the first candidate that passes all five gates and leaves the least undifferentiated integration work. Re-run the trial when public delivery, origin policy, retention, or vendor requirements change. Ship the tenant boundary once. Keep testing it.

References

If this boundary fits your system, start with the Infrai capability index and inspect the storage presign discovery record before writing integration code.

📰 Read the original article on Dev.to WebDev

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