Presigned Browser Storage Uploads Explained: 3 Large-File Deletion Boundaries
Short answer: use presigned POST for small, tightly constrained product-image submissions, a presigned PUT for a simple single-object transfer, and multipart upload for large files that must survive an interrupted browse
Short answer: use presigned POST for small, tightly constrained product-image submissions, a presigned PUT for a simple single-object transfer, and multipart upload for large files that must survive an interrupted browser session; whichever path you choose, treat upload completion and retention as separate state transitions.
For a B2B SaaS product catalog, the object is not the record. A tenant can remove an image while an export job is still reading it, abandon a half-finished upload, or retry the request that marks an upload complete. The runbook therefore needs three things before transfer speed enters the discussion: a tenant-scoped object key, an explicit lifecycle state, and a deletion policy that covers unfinished parts as well as completed objects.
I've been paged by missed scheduled work and duplicate delivery. That history makes one rule non-negotiable: retries are normal, so completion and deletion must be idempotent. Don't make a browser callback the sole evidence that a large file exists.
How should a browser choose presigned POST, PUT, or multipart for large files?
Choose by failure boundary, not by which request is shortest in a demo.
| Transfer path | Good fit | Operational catch | Deletion boundary |
|---|---|---|---|
| Presigned POST | A form submission where the server must constrain fields before accepting a product image | A dropped connection restarts the whole object | Delete or expire the completed object if the application never commits it |
| Presigned PUT | One known object key and a file small enough to resend | A retry sends the whole object again | Keep the object provisional until server-side verification succeeds |
| Multipart | Large exports or images where resuming individual parts matters | The application must track upload ID, part numbers, and completion | Abort incomplete sessions, then apply normal retention only after completion |
POST is useful when submission policy is the main control. PUT is the smallest moving system: issue one short-lived authorization, send one object, verify it, and commit the database row. Multipart adds bookkeeping in exchange for a narrower retry unit. A failed part can be sent again without resending every byte that already arrived.
That last property is why multipart is usually the right default for genuinely large files over unreliable client networks. It isn't automatically the right choice for every image. Part tracking, concurrent requests, browser persistence, and cleanup all become production responsibilities; below the size at which whole-file retries hurt your service objective, a single PUT is easier to operate. Your mileage may vary because the useful threshold depends on file-size distribution, client bandwidth, memory limits, and the storage service's multipart rules. Measure those inputs rather than copying a universal cutoff.
Presigning changes who carries the bytes, not who owns authorization. The application server should derive the tenant prefix and object identifier; the browser shouldn't submit an arbitrary destination key. It should also bind the intended operation, content constraints that the selected signing mechanism supports, and a short validity window. After transfer, the server verifies the expected object before changing application state. A successful browser request alone isn't enough evidence for an export workflow.
Read the deletion race as an incident timeline
The useful model has at least pending, available, deleting, and deleted. Walk one race from left to right. A tenant starts a multipart image upload, so the pending record owns a provisional key and upload ID. The browser finishes its last part just as a scheduled export snapshots the catalog. Before completion is committed, an administrator deletes the product. The completion retry now arrives late. It must not turn the image back into an available asset. A compare-and-set against pending fails after deletion has claimed the record; the completion worker reads the tombstone, acknowledges the retry, and asks storage to abort or remove the provisional data. Meanwhile, the export follows the product contract chosen in advance: either its snapshot is allowed to finish with the old image, or it fails closed and is regenerated. The worker never invents that answer during an incident. This single timeline exposes why the object is not the record, why callbacks need idempotency, and why deletion intent must outrank stale completion.
Retries happen.
The clocks remain separate. Product-image retention may follow tenant configuration, while generated exports may have a much shorter expiry because they duplicate catalog data. An unfinished multipart session follows a third clock: it is never a valid product asset, so an age-based sweeper can abort it after the application's retry window. Don't apply the completed-object retention rule to abandoned parts. They have different evidence and different owners.
The catch is that multipart is not suitable when your team cannot operate reconciliation and expiry jobs. Stick with a single PUT for modest files in that case, and accept whole-file retry cost. Likewise, POST is a poor fit when resumability is the primary requirement. These are reliability trade-offs, not a ranking of vendors.
Implement the tenant state machine in Go
Keep policy on the server, even though the browser uploads directly. The browser asks for an upload plan; the server chooses the mode, generates a tenant-owned key, persists a pending record, and returns time-limited transfer instructions. This Go example isolates the decision from any storage SDK so it can be tested without credentials:
package upload
import (
"errors"
"fmt"
)
type Mode string
const (
ModePost Mode = "post"
ModePut Mode = "put"
ModeMultipart Mode = "multipart"
)
type Request struct {
TenantID string
ObjectID string
SizeBytes int64
ContentType string
}
type Policy struct {
MultipartThreshold int64
MaxImageBytes int64
}
type Plan struct {
Key string
Mode Mode
}
func (p Policy) PlanImage(r Request) (Plan, error) {
if r.TenantID == "" || r.ObjectID == "" {
return Plan{}, errors.New("tenant and object IDs are required")
}
if r.SizeBytes <= 0 || r.SizeBytes > p.MaxImageBytes {
return Plan{}, errors.New("image size is outside policy")
}
key := fmt.Sprintf("tenants/%s/pending/%s", r.TenantID, r.ObjectID)
if r.SizeBytes >= p.MultipartThreshold {
return Plan{Key: key, Mode: ModeMultipart}, nil
}
if r.ContentType == "image/jpeg" || r.ContentType == "image/png" {
return Plan{Key: key, Mode: ModePost}, nil
}
return Plan{Key: key, Mode: ModePut}, nil
}
The numbers belong in configuration because they are operational policy, not protocol truth. Test around each boundary: zero bytes, exactly the multipart threshold, one byte below it, and the maximum allowed image size. Also test that one tenant can never obtain a key rooted under another tenant. Short code, sharp invariants.
The completion handler needs an idempotency key and a compare-and-set transition from pending to available. For multipart, it records the expected parts before requesting completion and treats a repeated completion command as a read of the existing result. For deletion, use the immutable application object ID to locate the stored key, mark the row deleting, and enqueue work with a deduplication key. A queue may deliver twice. The second execution should find either the same object or the tombstone and report success.
Downloads need equal care. If an export response supplies a filename, Content-Disposition defines whether content is presented inline or as an attachment and supports filename parameters. Generate the name from trusted metadata, preserve the tenant authorization check before issuing access, and avoid treating a display filename as an object key. The MDN reference covers the response-header syntax and browser-facing behavior.
Roll out with failure injection and a rollback switch
Deploy the plan endpoint before enabling direct transfer in the browser. In a staging tenant, exercise a completed POST, a repeated PUT, an interrupted multipart upload, a duplicate completion command, deletion during export generation, and a stale browser retry after deletion. Verify storage state and application state independently.
A green UI isn't a verification method.
Production signals should expose counts and age distributions for pending uploads, incomplete multipart sessions, completion retries, objects stuck in deleting, and exports referencing tombstoned assets. Alert on the oldest item rather than raw volume alone; a busy upload hour can be healthy, while one old pending object can prove that reconciliation stopped. Correlate every event with tenant ID, immutable object ID, and upload ID, but keep presigned credentials and full authorization URLs out of logs.
Rollback has two layers. First, stop issuing new multipart plans and fall back to the established single-transfer mode for files within its limit. Existing multipart sessions still need their completion or abort path; disabling the UI doesn't clean them up. Second, leave state records intact while rolling back application code. Deleting records to make a dashboard look clean destroys the evidence the reconciler needs.
Cost belongs in the verification loop, but it should not lead the choice. Request counts, retained bytes, unfinished parts, retrieval, and egress can be billed differently, so replay your workload against the provider's current policy; the Backblaze B2 pricing page is one public example of how a storage service documents those dimensions. I'm not sure any static comparison stays useful for long. A current bill plus a controlled workload resolves that uncertainty better than an old per-gigabyte table.
The final go/no-go check is simple: interrupt any step, repeat it, and confirm that tenant isolation and deletion intent survive. If they do, POST versus PUT versus multipart has become a controlled implementation detail instead of an incident source.
References
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.