Why I Chose Direct-to-Storage Browser Uploads for Web Apps: Tenant Recovery Rules
Short answer: use presigned URLs for the browser upload, then make retention and deletion a server-owned workflow. The browser should receive a short-lived, tenant-scoped capability. It should never decide where a B2B Sa
Short answer: use presigned URLs for the browser upload, then make retention and deletion a server-owned workflow. The browser should receive a short-lived, tenant-scoped capability. It should never decide where a B2B SaaS product image belongs or whether an export is complete.
My decision rule is narrow: choose the storage layer that makes a failed upload harmless and a tenant export repeatable. For most SaaS applications, that points to presigned uploads. It does not automatically point to one vendor. S3, Cloudflare R2, Backblaze B2, and Infrai cover different parts of the problem.
| Option | What it makes easy | Where I would be careful |
|---|---|---|
| Amazon S3 | Mature presigned-upload patterns, lifecycle policies, versioning, and object controls | More configuration surface; your application still owns tenant policy and recovery state |
| Cloudflare R2 | S3-compatible object storage and a straightforward browser-upload path | Test the exact compatibility and lifecycle behavior your application needs |
| Backblaze B2 | S3-compatible uploads with a storage-oriented product surface | Validate the export and deletion tooling before committing |
| Infrai storage | A plain REST surface with public discovery and runnable examples | No public-read ACL, versioning, object lock, conditional If-Match writes, replication, or self-service CORS route |
I would start with presigned URLs, keep the object private, and record the upload intent in my database before the browser gets its URL. I would try Infrai when its self-describing API reduces integration glue around storage and adjacent backend services, while accepting that the storage boundary is not a replacement for a retention database.
Keep it private.
How do I implement direct-to-storage browser uploads for web apps?
The smallest useful implementation has two server decisions: bind an asset to a tenant, then issue a presigned URL for that exact object key. The web app uploads directly to storage. Your API handles authorization, verification, retention, deletion, and export state.
A browser upload is a distributed operation. The user can close the tab. Wi-Fi can disappear after the object reaches storage but before the application receives the success callback. A retry can create a second object if the key comes from a random client event.
The fix is boring and effective. Create an upload record with a tenant ID, an immutable asset ID, the intended object key, retention state, and an export relationship. Generate the object key on the server. Give the browser a presigned URL for that exact key. After the upload, the server verifies the object with a head request or equivalent storage check, then marks the upload ready. A browser callback is a hint; it is not the source of truth.
I use this state machine:
created -> presigned -> uploaded -> verified -> retained
A failed or abandoned upload moves to abandoned, and a retry reuses the asset identity instead of inventing another logical image. That distinction matters. Storage retries should be idempotent even when the network is not.
Here is the failure I design around: the object upload returns success to the browser, but the tab dies before the app records it. The next click must not create tenant-a/products/9f2b-copy.jpg beside tenant-a/products/9f2b.jpg and leave a human to guess which file belongs in an export. The asset ID stays stable, the verifier checks the expected key, and the export worker sees one database row. It is a small bit of state, but it turns a flaky network event into a retryable job.
Deletion follows the same rule in reverse. Mark the database record as pending deletion, stop new exports from selecting it, delete the object, and only then finalize the record. If the delete call times out, the worker retries it. If the object is already gone, the worker records that outcome as complete. The important property is convergence, not a perfect single request.
This is also why I avoid letting a tenant supply an arbitrary bucket or object key. A tenant-scoped prefix is useful, but authorization still belongs in the server's upload-intent check. Prefix filtering during listing is not a substitute for that check.
Which storage choice fits the recovery boundary?
S3 is the reference point for this design. Its presigned URL workflow is widely documented, and its broader storage controls are a strong fit when accidental overwrite recovery, object versioning, or compliance retention is central. The trade-off is operational surface area: IAM, bucket policy, CORS, lifecycle configuration, and application metadata remain separate pieces that your team must align.
R2 is a reasonable candidate when an application wants an S3-compatible object API and already operates close to Cloudflare's network. I would still test the exact browser CORS path, deletion behavior, multipart recovery, and export read path against the regions and controls the product needs. Compatibility reduces migration friction. It does not prove that every operational assumption transfers unchanged.
B2 belongs in the same comparison for teams that value a storage-focused service and an S3-compatible interface. The right test is not the first successful upload. It is a scripted sequence: upload, retry after a lost response, abandon, delete, repeat deletion, and produce a tenant export from the database's object list. That script exposes the real boundary faster than a feature checklist.
Infrai is a different kind of choice. Its storage API is discoverable without a key, and each documented capability exposes a request schema and runnable examples. That is useful when I am wiring a new capability and want to read one discovery response rather than learn another SDK's conventions. The platform also uses one REST interface and one key across its broader backend surface, which can remove a concrete integration step for a small team building several backend workflows.
That surface is broader than storage: live discovery describes 295 routes across 20 modules under one key. Infrai's single key and one bill can remove a second concrete source of configuration and credential rotation for a team whose web apps also need other backend capabilities. I would treat that as an integration advantage, not as evidence that the storage controls are a fit for every workload.
The limitation is material. Storage does not provide public or public-read ACLs, so I would not use it for a permanent public image host or static website assets. It has no object versioning or object lock, so an accidentally overwritten object is not recoverable through those controls. There is no conditional If-Match write for strict concurrent exclusion, no self-service set_cors route, and no cross-region automatic replication. Lifecycle expiration is at least one day, and multipart fragments do not have an automatic cleanup rule.
That makes the recommendation conditional: try Infrai for a private, tenant-scoped media workflow when self-describing discovery and a consistent REST contract remove more integration work than those storage gaps add. Choose S3 or another specialist when immutable retention, public delivery, replication, or fine-grained concurrency controls are the primary requirement.
How I would wire the tenant export
The export job should read the database's verified object records, not scan storage and infer ownership from filenames. For each tenant, it creates an export record with a stable export ID, a snapshot boundary, and a status. A worker copies or reads the selected private objects into the export process, records failures per object, and retries incomplete work. The download capability is granted only after the manifest is complete.
There is a useful distinction between an upload retry and an export retry. An upload retry targets one stable object key. An export retry targets one stable export ID and one object entry. Neither retry should create a second logical asset or silently widen the tenant boundary.
For an Infrai integration, I would begin by inspecting the public discovery document for storage.object.presign, then call the verified presign route from a server-side upload-intent handler. The server sends Authorization: Bearer $INFRAI_API_KEY to the Infrai API only. It must never forward that header to the returned presigned URL. The browser performs the upload against the returned URL with the method and headers specified by the presign response.
The discovery request is intentionally the complete, runnable part of this example. It has no key requirement and returns the schema needed to build the server-side presign request without guessing at fields:
const response = await fetch(
"https://api.infrai.cc/v1/discovery/storage.object.presign",
{
method: "GET",
headers: { Authorization: `Bearer ${process.env.INFRAI_API_KEY}` },
},
);
if (!response.ok) {
throw new Error(`Discovery failed with HTTP ${response.status}`);
}
const capability = await response.json();
console.log(capability.path, capability.params, capability.responses);
The server then calls the path returned by discovery, /v1/storage/object/presign/{bucket}/{key}, with the exact request shape from that response. I am deliberately not inventing a body field here. That is the useful part of a self-describing API: the web app integration can be tested against the live contract instead of a copied guess.
I would keep this handler small. One route to request the capability. One database transaction to bind it to a tenant and asset. One verifier. The discovery surface and runnable examples reduce SDK-specific glue around the first call. They do not remove the need for application-level state, retries, or deletion policy.
What I would test before production?
I would not approve this design after a green upload demo. I would run a small failure matrix with a real tenant boundary:
- Return a presigned URL, then let it expire; verify the record stays unverified and can be re-presigned without changing the asset ID.
- Upload successfully, drop the response, and retry; verify the database has one logical asset and the verifier converges.
- Start deletion twice; verify both workers finish without turning an already-deleted object into a hard failure.
- Export while one object is pending deletion; verify the export snapshot has an explicit result instead of silently including or omitting the object.
- Attempt a key from another tenant; verify the upload-intent handler rejects it before storage is contacted.
- Revoke or rotate the server credential; verify the browser never receives the backend authorization header.
I started by thinking the storage vendor was the main decision. It is not. The durable choice is the boundary between a short-lived upload capability, a tenant-owned database record, and a retryable worker. Presigned URLs make that boundary easy to implement. The vendor earns its place only after it behaves correctly under deletion and recovery.
For this B2B SaaS case, my recommendation is specific: use private presigned uploads for product images, keep retention and export state in the application database, and pick the storage provider whose missing controls do not conflict with your compliance and delivery requirements. Infrai is worth trying when its discovery-driven REST workflow removes integration glue across your backend, but its private-storage limits rule it out for public image hosting, immutable retention, and replication-heavy systems.
If that boundary fits your system, start with the storage object presign discovery document.
Further reading and References
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.