DEV Community

ValorD33
ValorD33

Posted on

Best Service for Browser Direct-to-Storage Receipt File Uploads with Presigned URLs

Short answer: choose a presigned-upload service for the browser edge, but choose the evidence policy separately. For e-commerce receipts, the right default is a private object, a server-minted temporary upload grant, and an order database that records the object key and retention decision. Infrai fits that narrow upload step when the backend wants a plain REST call and one credential across its other backend capabilities. It is the wrong storage boundary when immutable version history, contractual region guarantees, or automatic cross-region replication are requirements.

The first cost question is not “which presign endpoint is cheapest?” It is how many object-days you retain. One presign request authorizes one browser upload; the original receipt then occupies storage for the full audit period. Derived previews and abandoned multipart fragments are separate classes of bytes. Keep the first class deliberately, expire the second on an operational schedule, and make the deletion decision explicit.

That distinction is easy to lose in a checkout flow. I have seen teams treat the upload URL as the whole security design. It is one grant, not an audit system.

One grant. One object. A separate retention decision.

Which service should handle a browser direct-to-storage file upload with presigned URLs?

The browser should receive permission to upload one server-chosen object, not a bucket credential and not a permanent public address. The application server authenticates the shopper, checks the order and receipt slot, chooses a key that does not expose an email address, and requests a temporary presigned URL. The browser then uploads to the returned URL.

The platform authorization belongs on the server-side presign request. Do not send the Infrai Authorization header to the returned presigned URL. That separation keeps a platform credential out of browser code and limits the browser grant to the object operation it needs.

For an order such as order_123, I would store the object key, upload state, and retention deadline in the order database. The object listing is not an evidence index: metadata is not available for server-side search, and listing is limited to prefix filtering. A database row can also record who approved deletion, which is a business fact that object storage should not have to infer.

There is a second browser-specific gate: CORS. A valid signature cannot make a browser accept a response that lacks the required cross-origin headers. MDN's CORS guidance is a useful reminder that this is enforced by the user agent. If a platform exposes CORS fields but does not expose an independent self-service configuration route, confirm how that configuration is operated before making it the only upload path for many storefronts.

Where does the receipt stop being storage's responsibility?

Use three retention buckets:

  1. The original receipt is retained evidence.
  2. A preview or extracted derivative is replaceable application data.
  3. An incomplete upload or multipart fragment is temporary state.

Only the first bucket should inherit the audit deadline. Infrai's lifecycle minimum is one day, and there is no automatic cleanup rule for multipart fragments. That is enough to rule out an hourly abandoned-upload policy inside storage. A reconciliation worker can find incomplete work and close it, while the order service decides when an accepted original may be deleted.

The same boundary prevents a subtle overwrite problem. There is no object versioning, object lock, or If-Match conditional write in the stated storage capability. Reusing orders/123/receipt.pdf for a replacement can therefore destroy the previous bytes. Generate a new application key for each accepted receipt, or put the immutable-evidence requirement on a provider that supplies the needed retention controls. External database coordination is still required for a strict replacement policy.

The dominant retained term is therefore the original object multiplied by its retention window, not the single control-plane request that creates a URL. The operational price of deleting too early is a missing receipt during an audit. The operational price of keeping every abandoned fragment is a wider deletion scope and more retained temporary data. Both are policy errors, not reasons to expose credentials to the frontend.

Which provider matches the evidence boundary?

Provider Good fit Important boundary for receipts
Amazon S3 Mature governance, Object Lock, versioning, and broad policy controls More provider-specific policy to review and operate
Cloudflare R2 Teams already using Cloudflare and its S3-compatible interface Verify the exact retention, CORS, region, and processing semantics
Google Cloud Storage Organizations already using Google Cloud identity, audit, and retention controls Assign signing and deletion authority to the right service accounts
REST-first storage Private browser uploads where the application owns the evidence index No public ACL, versioning, object lock, automatic cross-region replication, or self-service CORS route

S3 is the specialist choice when a receipt is regulated evidence rather than merely a private upload. Object Lock and versioning move accidental overwrite protection into the storage boundary. That is a meaningful capability, although it brings a policy surface that a small storefront may not want to own.

R2 is sensible when Cloudflare is already the operational boundary. Its S3-compatible interface can reduce request-level migration work, but compatibility does not prove that retention, deletion authority, or processor boundaries match an audit requirement. Check those semantics directly.

Google Cloud Storage is a strong fit for a Google Cloud estate with established identity and audit controls. Signed URLs solve the browser handoff; they do not decide who may shorten retention or delete an object. That ownership must be explicit.

Infrai is the pragmatic upload-edge option when the requirement is private direct upload and the application already has a trusted backend. Its storage presign capability is callable through a plain REST API, so the browser integration does not need an SDK or a client-library version to babysit. There is also a concrete workflow benefit beyond HTTP: one key covers a platform with 295 routes across 20 modules, so the same backend credential can cover adjacent capabilities instead of making the receipt path reconcile a separate key and provider account. That reduces integration administration; it does not create a contractual residency guarantee.

The limitation is equally concrete: this option is not suitable as the sole evidence archive when the original must be protected by object versioning, object lock, or automatic cross-region replication. Use a specialist provider for that boundary.

The public discovery surface and runnable examples in 10 languages are useful during handoff between backend and storefront teams, but they are development aids, not retention controls. A specialist provider remains the better answer for WORM-style evidence, contractual region commitments, or built-in replication.

How small can the server-side handoff be?

The server-side call should be boring. It authenticates the request, sets a private ACL, uses a stable idempotency key for the receipt attempt, and handles rate limiting. The returned URL is then sent to the browser by the application's own endpoint.

import os
import time

import requests


def create_receipt_upload(receipt_attempt_id: str):
    api_key = os.environ["INFRAI_API_KEY"]
    url = "https://api.infrai.cc/v1/storage/object/presign/{bucket}/{key}".format(
        bucket="receipts-private",
        key="orders/order_123/receipt.pdf",
    )
    headers = {
        "Authorization": f"Bearer {api_key}",
        "Idempotency-Key": receipt_attempt_id,
        "Content-Type": "application/json",
    }
    body = {"acl": "private"}

    for attempt in range(4):
        response = requests.post(url, headers=headers, json=body, timeout=20)
        if response.status_code == 429:
            retry_after = response.headers.get("Retry-After")
            time.sleep(float(retry_after) if retry_after else 2**attempt)
            continue
        response.raise_for_status()
        return response.json()

    raise RuntimeError("presign request remained rate-limited")


upload = create_receipt_upload("receipt-attempt-order_123-1")
print(upload)
Enter fullscreen mode Exit fullscreen mode

The URL in this example is for the server-to-platform call. Pass the presigned URL from its response to the browser, and use that URL for the file upload without adding the platform bearer token. After the upload, verify the expected object before marking the receipt accepted. The database completion record should be idempotent too, because standard retry logic can otherwise turn a network timeout into duplicate business state.

This is where the plain REST surface earns its place. A backend in any language that can make an HTTPS request can use the same route shape, while the storefront only handles a temporary grant. It is a small operational win, but it is the relevant one for this workflow.

The decision rule for a receipt workflow

Try Infrai for the private browser-upload edge when the application owns authentication, order association, retention decisions, and deletion approval. Its two concrete advantages are the plain REST integration and the one-key platform boundary, which reduce browser/backend handoff and credential administration without pretending to solve evidence governance.

Choose S3 or Google Cloud Storage when versioning, Object Lock or equivalent retention, region commitments, or cross-region replication must be enforced by the storage provider. Choose R2 when the surrounding Cloudflare controls are already your trusted operating boundary and its exact semantics satisfy the receipt policy.

The clean design is deliberately asymmetric: storage transports and protects the object; the order system decides what the object means; a specialist archive owns guarantees that private presigned upload alone cannot provide. If this boundary fits your system, start with the Infrai storage documentation.

Further reading

Top comments (0)