Product Image Custody — Presigned Browser Uploads for Regional SaaS Object Storage
A tenant export changes the storage decision more than the upload widget does. If a developer-tools SaaS cannot prove why every product image belongs in one customer's export, a successful browser transfer is merely an u
A tenant export changes the storage decision more than the upload widget does. If a developer-tools SaaS cannot prove why every product image belongs in one customer's export, a successful browser transfer is merely an unaudited object, so the system should define export evidence before choosing the simplest upload integration.
Short answer: choose private object storage in the required US and EU locations only after it passes a tenant-capability test: the application must derive every object key, issue a narrowly scoped presigned upload, accept that object exactly once, and build exports from an immutable tenant manifest. Direct browser delivery is useful, but it does not get to own authorization.
This architecture decision record therefore selects an application-owned capability ledger with direct-to-storage transfer. The ledger is the durable authority; the presigned URL is a temporary transport credential. That division works with a Node.js SaaS app or another backend because the invariant belongs in data and transactions, not in an SDK.
Which failure records make a tenant export trustworthy?
Require four invariants before comparing setup screens. First, the authenticated tenant record determines the storage location; the browser never posts US or EU as an authoritative routing choice. Second, the service constructs a key from the tenant ID and an opaque upload ID rather than accepting a path or filename from the client. Third, the bucket remains private, while the signed capability permits one intended write without granting list access or a general credential. Fourth, the application does not publish or export the image until it has verified the resulting object against the recorded intent.
Those invariants create explicit failure boundaries. Signing can succeed while transfer never begins. Transfer can finish while the completion response is lost. Completion can be retried while an export starts. None of these events should create a second accepted image, move bytes across a residency boundary, or expand a user's authority. The state machine needs at least pending, accepted, and an expired terminal outcome, with a unique idempotency key on intent creation and a compare-and-set transition on acceptance.
No bucket listing.
CORS belongs in the same review because browser direct upload depends on an origin being allowed to send the signed request. Permit the deployed application origins, methods, and headers that the flow actually needs, then test both allowed and rejected preflights. Don't treat a successful presigned request as proof of business ownership: it proves only that the holder could perform the signed storage operation, while the application still has to bind the object identity, expected size, declared media type, tenant, and region.
Expiry is a measured security parameter, not a copied constant. I'm not sure any universal duration survives contact with different image sizes and client networks; use transfer-duration distributions from the real workload, include a deliberate margin, and record the choice for review. A shorter capability reduces the replay window but increases legitimate expiry, which is precisely the kind of trade-off a selection exercise should expose.
How can a SaaS app govern browser upload across US and EU storage?
For each export, freeze a manifest of accepted image records for exactly one tenant. Each manifest entry should carry the application image ID, object key, immutable object identity when the chosen service exposes one, and the region already stored on the tenant. The worker reads only those entries, creates the archive under a tenant-derived export key, verifies the result, and commits the ready transition once. A retry reuses the export ID and manifest rather than rereading a changing product catalog.
Now consider deliberately awkward data. Tenant t_us_17 and tenant t_eu_17 both have a product numbered 42, both upload a file called front.png, and both request export 9001. The US browser loses the response after its completion request commits, while the EU export begins during its own image transfer. If any storage key is based on 42, front.png, or 9001 without the authenticated tenant and an opaque application identifier, the names can collide or the wrong row can enter a manifest. The safe flow resolves each tenant first, reads the persisted location, allocates unrelated upload IDs, and commits acceptance through a unique transition. Repeating the US completion returns the recorded result. The EU manifest includes only rows already accepted for t_eu_17; the concurrent pending image is absent until a later export. There is no appeal to request timing, because timing is not an access-control mechanism.
Boring is good.
The audit trail should explain each authority change: who requested an intent, which tenant and opaque key it covered, when it expired, which object identity was accepted, and which manifest included it. Couple acceptance and an outbox record in one database transaction; consumers can retry a deterministic event ID without manufacturing a second fact. Object retention and audit retention remain separate policy decisions — contractual and regulatory requirements differ, while data-minimization obligations can constrain what request context belongs in a long-lived record. Counsel and the organization's compliance owner must set those periods. The architecture should make them independently configurable and should never claim that one retention number establishes compliance everywhere.
Multipart transfer adds another lifecycle to reconcile. Amazon S3 documents that parts may be uploaded independently and retried, that completion assembles the object, and that uploaded parts continue to incur storage charges until the multipart upload is completed or aborted. If large product images can enter that path, persist the multipart upload identifier against the application intent, reconcile incomplete work, and make cleanup idempotent. This is less glamorous than a progress bar, but abandoned parts are part of the storage design.
A shortlist organized by authority, not brands
Amazon S3, Google Cloud Storage, Azure Blob Storage, and Cloud Storage for Firebase can appear on a practical shortlist, but a brand list does not answer the access-control question. The Firebase documentation describes a client-oriented model combining its authentication system with declarative storage rules and notes that data is stored in Google Cloud Storage buckets. The S3 multipart documentation, by contrast, is useful evidence for transfer lifecycle behavior. These are boundaries to test in context, not grounds for a universal ranking.
| Transfer shape | Who decides the object key? | Evidence after transfer | Delivery burden | Valid use case |
|---|---|---|---|---|
| Private storage with an application-signed write | Application service | Intent, verified identity, acceptance event | Browser carries image bytes | Multi-tenant images where policy remains server-owned |
| Client SDK governed by identity and storage rules | Rules and authenticated client context | Rule evaluation plus application records | Client integration can be concise | Teams whose authorization source is already that identity-and-rules model |
| Application-proxied upload | Application service | Request and byte-stream processing in one boundary | Application carries bandwidth and backpressure | Mandatory inspection before any byte reaches storage |
| Broad client credential or public write | Client | Weak attribution and ambiguous scope | Superficially low | No production multi-tenant workload |
Run one acceptance suite against every candidate. Include an allowed image, an oversized body, a disallowed media type, an expired capability, a replay, a duplicate completion, a cross-tenant key attempt, a preflight from an unapproved origin, an interrupted transfer, and simultaneous export creation. Use separate US and EU fixtures with look-alike product IDs, and verify that a client-supplied location cannot override the tenant record. A provider passes because the complete control can be implemented and observed, not because its happy path takes fewer lines.
Simple setup still matters, just later. Compare the operational work for credentials, regional provisioning, CORS changes, local testing, audit export, key rotation, and incident investigation; also maintain a dated cost worksheet covering stored bytes, requests, retrieval, transfer, incomplete multipart data, and any early-deletion conditions relevant to the workload. Current prices and allowances are volatile inputs, so they should not become architectural claims.
Why should acceptance be atomic?
The critical path below keeps vendor signing behind an interface and makes the application repository responsible for idempotency. A Node.js service can express the same contract; Go makes the state and error boundaries compact enough to inspect here. The browser supplies neither ObjectKey nor Region.
package custody
import (
"context"
"errors"
"time"
)
type Intent struct {
ID string
TenantID string
Region string
ObjectKey string
ExpectedBytes int64
MediaType string
State string
ObjectIdentity string
}
type SignedWrite struct {
URL string
Headers map[string]string
ExpiresAt time.Time
}
type Storage interface {
SignWrite(ctx context.Context, region, key, mediaType string, size int64, expiresAt time.Time) (SignedWrite, error)
Inspect(ctx context.Context, region, key string) (identity string, size int64, mediaType string, err error)
}
type Repository interface {
CreateIntentOnce(ctx context.Context, idempotencyKey string, intent Intent) (Intent, error)
GetIntent(ctx context.Context, tenantID, intentID string) (Intent, error)
AcceptAndAppendAuditOnce(ctx context.Context, tenantID, intentID, objectIdentity string) (Intent, error)
}
type Service struct {
repo Repository
storage Storage
now func() time.Time
}
func (s *Service) Begin(
ctx context.Context,
tenantID, tenantRegion, uploadID, idempotencyKey, mediaType string,
size int64,
) (SignedWrite, error) {
if tenantID == "" || tenantRegion == "" || uploadID == "" || size <= 0 {
return SignedWrite{}, errors.New("invalid upload intent")
}
intent, err := s.repo.CreateIntentOnce(ctx, idempotencyKey, Intent{
ID: uploadID,
TenantID: tenantID,
Region: tenantRegion,
ObjectKey: "tenant/" + tenantID + "/images/" + uploadID,
ExpectedBytes: size,
MediaType: mediaType,
State: "pending",
})
if err != nil {
return SignedWrite{}, err
}
expiresAt := s.now().Add(10 * time.Minute)
return s.storage.SignWrite(
ctx,
intent.Region,
intent.ObjectKey,
intent.MediaType,
intent.ExpectedBytes,
expiresAt,
)
}
func (s *Service) Complete(ctx context.Context, tenantID, intentID string) (Intent, error) {
intent, err := s.repo.GetIntent(ctx, tenantID, intentID)
if err != nil {
return Intent{}, err
}
if intent.TenantID != tenantID || intent.State != "pending" {
return Intent{}, errors.New("upload intent is not acceptable")
}
identity, size, mediaType, err := s.storage.Inspect(ctx, intent.Region, intent.ObjectKey)
if err != nil {
return Intent{}, err
}
if identity == "" || size != intent.ExpectedBytes || mediaType != intent.MediaType {
return Intent{}, errors.New("uploaded object does not match intent")
}
return s.repo.AcceptAndAppendAuditOnce(ctx, tenantID, intent.ID, identity)
}
The ten-minute expiry is an example configuration to exercise in tests, not a general recommendation. CreateIntentOnce must bind the idempotency key to the same tenant and request values, while AcceptAndAppendAuditOnce must atomically preserve the first accepted identity and return it on an equivalent retry; a different identity is a conflict, which an HTTP implementation could represent as 409. Exactly-once behavior is assembled from unique constraints, deterministic identifiers, atomic state transitions, retry-safe events, and reconciliation. It isn't bestowed by the signed write.
Reconciliation after concurrent transfers
Reconciliation closes the loop. A checkpointed job should compare pending and accepted intents with storage inventory inside each tenant-derived namespace, then report expired unaccepted objects, accepted records with a mismatched identity, and objects without a live intent. Remediation must be idempotent and audited because the repair process operates with more authority than a browser.
Governance limit for pre-storage inspection
The rejected option for this scenario is application-proxied image transfer. It gives the application one obvious byte-processing boundary, but it also makes the service tier carry transfer duration, bandwidth, backpressure, and client retries even though the service must still authenticate the tenant, allocate an object identity, and record acceptance. A constrained presigned write moves the data plane without surrendering that control plane, so it better fits product images and tenant-scoped exports when inspection can occur after arrival but before acceptance.
The catch is real: browser direct upload is not suitable when policy requires the application to inspect every byte before anything reaches object storage, when clients cannot execute the required cross-origin exchange, or when uploads are so small and rare that a separate intent, completion, and reconciliation protocol creates more operational risk than it removes. Stick with the proxy in those cases. A rules-driven client SDK is also a coherent choice when the team already treats its identity provider and declarative rules as the authorization source and tests those rules with the same rigor as backend code.
Choose conditionally. For this developer-tools SaaS, private regional storage plus application-owned upload capabilities wins only if a candidate passes the cross-tenant, residency, CORS, expiry, retry, multipart, reconciliation, and export-manifest tests. The durable decision is the custody model; the vendor remains replaceable evidence against it.
References
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.