# Browser-to-Storage File Intake: Testing CORS, Signed URLs, and Tenant Privacy

> Source: <https://dev.to/ronanhalewood782/browser-to-storage-file-intake-testing-cors-signed-urls-and-tenant-privacy-1b00>
> Published: 2026-11-16 13:17:19+00:00

A private document feature needs one decision before anyone debates upload speed: can the application accept a file only after it has landed in storage, or must it examine every byte before persistence? Short answer: use a browser-to-storage signed write for ordinary private documents that can be verified after upload; use a streaming server proxy when inspection or transformation must happen before storage accepts the stream.

The transfer route is only one state in the workflow. For an AI application, a file is not ready for extraction, chunking, or retrieval because a progress bar reached 100%. It becomes usable after authorization, storage verification, and an explicit acceptance transition agree. That distinction is where a surprising number of notebook demos lose their footing in production.

Start with a state model, not an endpoint. The application authenticates the caller, generates a storage key under a tenant-owned prefix, records the expected size and media type, and creates a pending upload record. It then grants one narrowly scoped write for a short period. The browser sends bytes to storage and returns to the application to finalize. A verifier checks the expected object before the record becomes accepted.

This keeps private storage private. A direct browser write changes the data path; it does not make the object readable by the public. Reads still require separate application authorization and a separately constrained delivery mechanism. The original filename is display metadata, not an object key chosen by the client.

CORS and a signed write answer different questions. CORS tells a browser whether it may make a cross-origin request. The storage authorization tells the storage service whether that particular method, target, expiration, and signed request are acceptable. An allowed origin cannot repair an expired grant or a request whose required headers differ from the signed ones.

I would make those rules executable before wiring an SDK or a web handler. This small Python policy function is deliberately boring: it expresses the constraint that decides the byte path, and it gives an eval harness a clean unit to exercise.

``` python
from dataclasses import dataclass
from enum import Enum

class TransferPath(str, Enum):
    BROWSER_WRITE = "browser_scoped_write"
    SERVER_PROXY = "streaming_server_proxy"

@dataclass(frozen=True)
class UploadPolicy:
    inspect_before_storage: bool
    transform_before_storage: bool
    browser_can_reach_storage_origin: bool
    signer_covers_required_headers: bool

def choose_transfer_path(policy: UploadPolicy) -> TransferPath:
    if policy.inspect_before_storage or policy.transform_before_storage:
        return TransferPath.SERVER_PROXY
    if not policy.browser_can_reach_storage_origin:
        return TransferPath.SERVER_PROXY
    if not policy.signer_covers_required_headers:
        return TransferPath.SERVER_PROXY
    return TransferPath.BROWSER_WRITE

def test_pre_storage_inspection_uses_a_proxy() -> None:
    policy = UploadPolicy(True, False, True, True)
    assert choose_transfer_path(policy) is TransferPath.SERVER_PROXY
```

The useful result is not “direct won.” It is a recorded reason for each route, which can be compared in an eval run and reviewed when a policy changes.

Not enough.

The tempting first implementation creates a database row, accepts bytes, and immediately queues document processing. It looks tidy until an interrupted upload leaves an object without a matching accepted row, a client retries finalization, or a tenant-scoped key was assembled from untrusted client input. Follow one of those cases through the system: the browser loses its connection after storage receives some bytes, the UI retries, and an eager worker sees a row that looks ready because the application made “upload complete” mean three different things. It may spend parsing time on the object, record chunks against an unverified tenant boundary, and make later cleanup harder because the database and storage now disagree about what happened. The fix is not a clever retry loop. It is a state transition that has one owner, observable preconditions, and a defined cleanup path when the expected object cannot be verified.

Keep the states separate: pending, stored, verified, accepted, rejected, and expired. The exact names do not matter. The irreversible boundary does. A downstream worker should consume accepted records only, and finalization should be idempotent so a retry returns the same outcome rather than scheduling duplicate extraction.

For a prompt-cost-aware RAG pipeline, this is more than storage hygiene. Parsing and embedding a document before its storage identity is verified spends compute on an artifact that may later be discarded. Put cheap structural checks first: tenant ownership, declared limits, expected key, observed size, and permitted type. Then let the async pipeline handle the expensive work after acceptance. There is no reason to let a partial browser transfer enter the same queue as a verified knowledge source.

Lifecycle rules deserve a place in this experiment too. Pending objects need an expiration policy, and accepted document retention needs its own product decision. Object lifecycle management can transition or expire objects according to rules, so test those rules against an isolated prefix before applying them to user documents; deletion behavior is part of the storage contract, not cleanup trivia [1].

A scoped browser write removes application workers from the byte path. That is usually a strong fit for larger files when post-upload verification is sufficient, but it creates a cross-origin boundary that needs deliberate configuration: the browser origin, the request method, and the headers used by the upload must match the allowed and signed request.

A streaming proxy keeps the browser on the application origin and lets the service enforce byte limits, inspect content, or transform the stream before storage. The catch is that the application now owns long-lived request handling, backpressure, bandwidth, cancellation, and safe retries. Do not read the entire body into memory; stream it through the service and define what a retry means after a partial transfer.

| Decision point | Scoped browser write | Streaming server proxy | 
|---|---|---|
| Byte path | Browser to private object storage | Browser through the application | 
| CORS dependency | Yes, for the storage origin | Usually no separate storage-origin policy | 
| Pre-storage inspection | Not in the application byte path | Available while streaming | 
| Application resource pressure | Control plane and finalization | Control plane plus file bytes | 
| Useful fit | Post-upload verification is acceptable | Inspection or transformation must precede storage | 

Small files change the answer. A low-volume internal tool may be simpler with a proxy because one request path is easier to observe. A large-file SaaS workflow often benefits from a scoped browser write because it preserves application concurrency for authorization and document processing. Your mileage may vary with browser controls, file size distribution, and compliance rules; measure those constraints rather than copying a diagram.

Use a production-shaped test set, not one successful PDF. Each case should land in a known state and emit an event that ties together the tenant, generated key, transfer path, and finalization result without logging document contents or credentials.

For each case, collect completion latency, abandoned-pending count, proxy memory high-water mark, finalization retry count, authorization failures, and the time from acceptance to a searchable document. Those are engineering signals, not a vendor scorecard. They tell a Python team whether the storage boundary is behaving as the ingestion system assumes.

There is a limitation worth stating plainly. A direct browser route is not suitable when the application must inspect the complete stream before persistence, when a required transform has to happen inline, or when the relevant browser environment cannot use the storage origin. Stick with a streaming proxy in those cases. Conversely, a proxy is poor fit when it turns large uploads into worker starvation and post-upload checks meet the actual policy.

The architecture to ship is the one whose failure states your team can explain, test, and clean up. Fast transfer helps. Accepted ownership is the release gate.
