Presigned URL Practices for High-Throughput Browser Receipt Uploads to Object Storage
Short answer: issue a short-lived, object-specific upload capability from your application, then make the upload path resumable, observable, and independently verifiable. For a customer-support system processing receipts
Short answer: issue a short-lived, object-specific upload capability from your application, then make the upload path resumable, observable, and independently verifiable. For a customer-support system processing receipts, the hard part is not creating a URL. It is preserving the original large file while making retries harmless, authorization narrow, and completion trustworthy.
The useful unit of design is a state transition: issued -> uploading -> uploaded -> verified -> retained. A browser can be interrupted at any point. The server should be able to reconcile the state later without trusting a success callback from a tab.
What does the on-call page actually mean?
The page usually arrives as a downstream symptom: receipt-processing backlog is growing, or the oldest unprocessed receipt has crossed its service objective. The on-call sees a queue age and a count of failed jobs. That is late.
Work backward to the upload signal. Track URL issuance, bytes accepted, upload duration, aborts, checksum failures, and the time between storage completion and application acknowledgement. Break those measurements down by object-size bucket, such as 0-10 MiB, 10-100 MiB, and over 100 MiB. A single average hides the large-file cliff.
The object key is evidence, not authorization.
The alert should distinguish a slow browser from a broken consumer. If bytes are arriving but verification is delayed, page on verification latency. If issuance succeeds but no bytes arrive, inspect browser, network, and policy failures. If storage reports completion but the application has no matching record, page on reconciliation age. Each alert points at a different control loop.
Thresholds have a cost. A low threshold catches a regional or network problem earlier, but it also pages during a handful of slow customer connections. A high threshold protects the on-call from noise and delays discovery. Start with a measured baseline for each size bucket, then review false positives after a week of ordinary traffic.
How do presigned URLs make browser uploads safer for object storage?
The application should authorize an upload before it signs anything. Bind the capability to the authenticated support case, an opaque object key, an allowed method, an expected content type, a maximum size, and an expiration window. Do not let a browser choose an arbitrary key or turn a receipt upload into a general-purpose storage credential.
Use a fresh object key for every upload attempt. Reusing a human filename creates collisions and makes audit trails ambiguous. A key can include a case identifier and a random suffix, but access checks should use the server-side case record rather than parsing trust from the key. Keep the original object immutable after verification; create a separate derived object for thumbnails, OCR text, or redacted output.
Presigned requests are bearer capabilities. Anyone holding one can use it within its permitted scope until it expires, so keep the URL out of application logs, analytics events, support screenshots, and query-string tracing where possible. A short expiry limits exposure, but it does not replace authorization at issuance or server-side ownership checks at completion.
The trap is the filename.
The browser should receive only the fields it needs to perform one upload. For a single-request upload, the client can send the file with the signed method and required headers. For a multipart upload, the server must track the upload identifier and each completed part, and it must expire or abort incomplete sessions. The second design has more bookkeeping, but it avoids forcing a large receipt through one fragile request.
How should retries behave for large receipts?
A retry is normal. A duplicate receipt is not. The application record needs an idempotency key generated for the support action, while each physical attempt gets its own object key. On retry, the server can reuse a known verified object or create a new attempt and retain the relationship between them. It should never silently overwrite an original file.
The browser can retry a failed part, but the server must verify the final object before marking the receipt ready. Useful checks include the expected size, a checksum supplied through the storage protocol, the object metadata, and the association with the case. A storage success response says that bytes were accepted; it does not prove that the right customer uploaded the right receipt to the right case.
Here is the important boundary in Go. The signer receives an already-authorized object description; it does not accept a raw path from the browser. The storage adapter can be replaced with another object-storage implementation without changing the authorization rule.
package upload
import (
"context"
"fmt"
"time"
)
type UploadRequest struct {
CaseID string
ObjectKey string
ContentType string
SizeBytes int64
}
// Signer is implemented by the storage adapter, not by the HTTP handler.
type Signer interface {
PresignPut(context.Context, string, string, int64, time.Duration) (string, error)
}
func IssueURL(ctx context.Context, s Signer, req UploadRequest) (string, error) {
if req.CaseID == "" || req.ObjectKey == "" {
return "", fmt.Errorf("missing authorized upload identity")
}
if req.SizeBytes <= 0 || req.SizeBytes > 512*1024*1024 {
return "", fmt.Errorf("receipt size is outside the upload policy")
}
if req.ContentType != "application/pdf" && req.ContentType != "image/jpeg" {
return "", fmt.Errorf("unsupported receipt type")
}
return s.PresignPut(ctx, req.ObjectKey, req.ContentType, req.SizeBytes, 10*time.Minute)
}
The 512 MiB boundary above is an example policy, not a universal limit. Set it from the largest legitimate receipt and the browser paths you support, then test near the boundary. The ten-minute lifetime is also a policy choice. A slow connection may need more time; a long-lived bearer capability increases the impact of leakage. Measure upload duration before changing it.
The trade-off is clear: direct browser transfer improves large-file throughput, but it adds reconciliation and leaves the client responsible for network behavior. It is a poor fit when every byte must pass through an inline inspection service before storage. In that case, a controlled relay may be the required boundary, even though it consumes more application bandwidth.
What should happen after the browser says done?
Treat the browser callback as a request to check state, not as proof. A worker or reconciliation loop should find objects that were uploaded but never acknowledged, and application records that claim completion without a verified object. This is where a missed job becomes visible before a customer reports it.
No callback is proof.
Keep these transitions durable and explicit. uploading can expire. uploaded means storage has reported completion. verified means the server checked size, checksum, metadata, and case ownership. retained means the retention policy has taken over. A receipt should not enter OCR or agent search from the uploaded state alone.
Deletion deserves the same care as upload. A support case may be erased under a data-subject request, yet an orphaned original can remain outside the application database. The deletion workflow needs an object inventory or durable object reference, a retryable delete operation, and an audit record that does not retain the deleted file itself. GDPR Article 17 describes the right to erasure and its exceptions; legal review still determines the retention rule for a particular business.
A practical decision rule
Use one-request uploads when files are small, the browser path is stable, and restarting the transfer is acceptable. Use multipart or resumable uploads when the file is large, connections are intermittent, or the cost of restarting from byte zero is material. In both cases, the application owns authorization and verification; object storage owns byte transfer and durability.
Retries happen.
Test the ugly paths deliberately: close the tab after part 3, replay the completion request, change the content type, let the URL expire, upload a file just over the limit, and delete the case while an upload is active. Observe queue age, orphan age, verification latency, and the distribution of upload durations. Those measurements tell you whether the design is working.
That is the handoff.
The conclusion is operational rather than product-specific: make the signed URL narrow, make retries idempotent, keep the original separate from derived files, and alert on the gap between storage completion and verified application state. That combination gives a support team a usable throughput path without turning a browser upload into an unbounded credential or an untracked audit liability.
Further reading
- https://www.rfc-editor.org/rfc/rfc7231
- https://www.rfc-editor.org/rfc/rfc9110
- https://gdpr-info.eu/art-17-gdpr/
- https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html
- https://cloud.google.com/storage/docs/access-control/signed-urls
- https://learn.microsoft.com/en-us/azure/storage/blobs/sas-service-create
Originally published by Dev.to Security. Aggregated on AIWithGhost for educational purposes โ full credit and traffic to the original publisher.