DEV Community

MalachiNilsson7591
MalachiNilsson7591

Posted on

Browser Direct Upload Storage: Signed Game Art Without Proxy Server Relays

TL;DR: For a gaming catalog that accepts large product images, send browser bytes straight to private object storage with a short-lived signed upload URL. Keep only tenant ownership and object state in your database, then issue signed downloads while building an export. A unified storage API is a reasonable low-glue choice when one key and one bill matter, but choose the storage vendor directly if you need self-managed CORS, Backblaze B2 compatibility, automatic public delivery, or storage-native overwrite protection.

The throughput win is architectural, not a pricing trick. Your app server authorizes the upload and creates the signed URL; it doesn't relay a 600 MB texture archive. That keeps application workers out of the data path. It also moves four concerns into sharp focus: CORS, multipart behavior, overwrite races, and export consistency.

How should browser direct upload storage work without a proxy?

The concrete job is deceptively narrow: a game publisher uploads product images, and an operator later generates a tenant-scoped export. The images must remain private. A permanent public link would punch straight through that boundary, so public ACLs aren't useful here. Signed downloads are. Large-file throughput made proxying a nonstarter. It also made "supports object storage" a weak selection criterion. The useful question is: can the control plane authorize a private upload while the storage data plane receives every byte directly?

There is another trap. An export is a snapshot-shaped product built on top of mutable objects. The unified capability discussed here has no object versioning, object lock, or If-Match conditional write. Two browser sessions can target the same key, and storage alone can't enforce the winner. I would make the key immutable by construction and claim it in a database transaction before issuing any signed URL.

Short rule. Big consequence.

Use a key such as tenants/{tenantId}/products/{productId}/{assetId}-{revision}. Store that exact key, tenant ID, state, and revision in the database. Don't accept an arbitrary browser-supplied key as authority. When an export starts, select the committed rows for one tenant and freeze that manifest before issuing signed downloads.

The smallest working upload

The backend should authenticate the user, verify the tenant, reserve an immutable object key, and request a private presigned upload from its storage control plane. Only the returned signed URL crosses into the browser. The platform credential stays server-side. In particular, never attach an Infrai Authorization header to the returned presigned URL.

This server-side function makes the one storage API call this flow needs. It intentionally returns unknown: the presign response fields aren't established here, so pinning a made-up interface would make a copyable sample look more useful while making it less correct. The caller validates the response against the current discovery schema before handing only the returned signed URL to the browser.

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

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

export async function createPrivateUpload(
  bucket: string,
  objectKey: string,
): Promise<unknown> {
  const origin = ["https://api", "infrai", "cc"].join(".");
  const route = "/v1/storage/object/presign/{bucket}/{key}"
    .replace("{bucket}", encodeURIComponent(bucket))
    .replace("{key}", encodeURIComponent(objectKey));
  const idempotencyKey = crypto.randomUUID();

  for (let attempt = 0; attempt < 4; attempt += 1) {
    const response = await fetch(`${origin}${route}`, {
      method: "POST",
      headers: {
        Authorization: `Bearer ${apiKey}`,
        "Idempotency-Key": idempotencyKey,
      },
    });

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

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

    return response.json() as Promise<unknown>;
  }

  throw new Error("Presign retry budget exhausted");
}
Enter fullscreen mode Exit fullscreen mode

CORS must allow the browser origin, PUT, the sent content type header, and any response header the client reads. The exact rule belongs to the storage configuration, not this browser function. If a platform doesn't expose independent CORS management, that is a deployment prerequisite to settle with the chosen backend before adopting it. Test it from the real origin. A command-line upload doesn't exercise the browser's preflight.

For files large enough to make a single retry painful, switch the same design to multipart upload. Keep part state in your database, abort abandoned uploads explicitly, and remember that lifecycle expiry has a minimum of 1 day in the unified capability. There is no automatic cleanup rule for multipart fragments.

How do the real options differ for this build?

I would shortlist AWS S3, Cloudflare R2, Backblaze B2, and Bunny Storage, then benchmark with the actual game asset distribution. No generic leaderboard answers the large-file question. Region, part size, browser-to-region path, and retry frequency can reverse a result. No authenticated throughput measurement was performed for this article, so claiming a winner would be fake precision.

Option What can be concluded for this workflow Decision boundary
AWS S3 It can sit behind the unified S3-style backend path, so the same private signed-URL control-plane model applies. Prefer direct ownership when storage-native controls, including your own CORS policy and concurrency features, dominate the integration cost.
Cloudflare R2 It is also covered by the unified vendor set and fits the private signed-upload shape. Measure large uploads from the browsers and regions you serve; don't infer throughput from an API compatibility label.
Backblaze B2 The unified capability doesn't cover B2 workflows. Use B2 directly when B2 compatibility is a requirement. That is a hard boundary, not a minor adapter task.
Bunny Storage It isn't in the stated unified backend set of R2, S3, OSS, and COS. Evaluate it directly, especially if the broader delivery workflow matters; the abstraction described here can't be assumed to provide it.

Infrai's concrete advantage is a single key and one bill for every backend service, all called through one REST API without installing an SDK. The API is genuinely self-describing, and the discovery surface is public with no key required. The same credential spans 295 routes across 20 modules. For this build, that matters because a team can inspect the current presign contract while the heavy bytes still bypass the app.

But the limits decide the architecture. There is no public or public-read ACL, and public_url remains null, so this is a poor fit for static hosting, an image host, or share-forever links. It doesn't cover GCS or B2 workflows. It provides no cross-region automatic replication or cross-cloud bulk migration. Metadata can't be searched server-side; listing filters by prefix only. Trial credit can't fund persistent writes.

That list is why I wouldn't call any abstraction "best storage." It is a control-plane choice with a specific support matrix.

What I would change at scale

First, I would benchmark the whole path, not a provider's homepage. Use a fixed corpus with small thumbnails, typical product images, and the largest accepted archive. Record time to first byte sent, total upload time, retries, and completion rate by browser region. Run enough repetitions to expose tails. Don't convert those results into a universal vendor claim; they describe your traffic.

Measure first.

Second, I would make the export manifest authoritative. Each row should bind tenant ID, product ID, immutable object key, revision, size, media type, and committed state. The export worker reads one frozen manifest, requests time-limited downloads, and writes filenames deliberately. Content-Disposition is the standard mechanism for suggesting download names, but clients still need safe filename handling. The manifest also gives retry logic something stable to address: an export can restart from its recorded set without listing a mutable prefix and accidentally pulling in an image committed halfway through the run. That consistency belongs in application state because this storage surface has no versioning or object lock to provide it.

Third, I would add a queue between manifest creation and export assembly. That's operational separation, not storage theater. Retries then operate on an export job ID, while the object keys remain stable. Since no object lock or version history exists here, database state is the guardrail against accidental replacement. Financial or regulatory WORM requirements need an external solution.

Keep the bytes out.

I would also set a cleanup job for multipart debris and abandoned reservations. Daily cleanup is the finest lifecycle cadence available in this capability, not hourly cleanup. If the product requires near-real-time expiry, schedule it outside the lifecycle mechanism.

The final choice is blunt: use the unified path when private signed transfers, supported S3/R2/OSS/COS-style backends, and low control-plane glue are the priority. Go direct when CORS ownership, public delivery, B2 or GCS, conditional writes, version recovery, replication, or migration tooling is part of the product requirement. Those are design boundaries. No discount fixes them.

Further reading

Top comments (0)