Short answer: use a single, authenticated upload for ordinary avatar files, and reserve multipart upload for objects large enough that retrying the whole request is more expensive than tracking parts. In a gaming receipt pipeline, keep the original receipt under a write-once audit key while serving a resized avatar from a separate, short-lived key.
That boundary is the decision record. The invariant is that an upload must be attributable to a player, a purchase, and a content hash before it becomes auditable. The failure boundary is the handoff from an untrusted browser to object storage: a valid HTTP response only says bytes were accepted, not that the object belongs to the right account or that the original can be found six months later.
What should beginners check before choosing small image upload, object storage, or multipart upload?
Start with the file distribution, not a folklore threshold. Measure p50, p95, and the largest accepted avatar, then account for mobile packet loss and your SDK's retry behavior. A 200 KB avatar normally does better as one request. A 200 MB receipt video may justify multipart because a dropped connection should not throw away every byte. Your threshold is a policy knob, not a storage law.
Measure first.
The browser should receive a narrowly scoped presigned request. The application, not the browser, decides the destination key and metadata. For receipts, write an immutable original such as receipts/{player_id}/{purchase_id}/{sha256}.bin; for avatars, write a versioned derivative such as avatars/{player_id}/{avatar_version}.webp. Store the object ID, hash, size, media type, and retention deadline in your database in the same workflow.
Here is the option record I use with a small team:
| Path | Good fit | Cost or failure trade-off |
|---|---|---|
| One authenticated PUT | Small avatar files and predictable networks | A retry repeats the entire body |
| Multipart upload | Large or variable receipts, resumable mobile transfers | More state: part numbers, completion, and abandoned-upload cleanup |
| Server relay | Strict inspection or transformation before storage | Your servers carry bandwidth and become another timeout boundary |
The catch is operational ownership. Multipart isn't suitable when nobody monitors incomplete uploads or when the object store's completion record cannot be reconciled with the purchase ledger; stick with a single request until those controls exist.
How do you implement the avatar and receipt critical path?
The following Python sketch keeps policy decisions on the server. It creates an upload intent, asks a storage adapter for a presigned URL, and records the receipt only after a HEAD check confirms size and digest. The adapter can wrap any S3-compatible service; the interface is the portability boundary.
from dataclasses import dataclass
from hashlib import sha256
from typing import Protocol
@dataclass
class UploadIntent:
player_id: str
purchase_id: str
key: str
max_bytes: int
content_type: str
digest: str
class ObjectStore(Protocol):
def presign_put(self, key: str, content_type: str, max_bytes: int) -> str: ...
def head(self, key: str) -> dict: ...
def make_intent(player_id: str, purchase_id: str, body: bytes, content_type: str) -> UploadIntent:
if len(body) > 10 * 1024 * 1024:
raise ValueError("avatar exceeds 10 MiB policy")
if content_type not in {"image/jpeg", "image/png", "image/webp"}:
raise ValueError("unsupported avatar media type")
digest = sha256(body).hexdigest()
key = f"avatars/{player_id}/{digest}.webp"
return UploadIntent(player_id, purchase_id, key, 10 * 1024 * 1024, content_type, digest)
def finalize_receipt(store: ObjectStore, intent: UploadIntent) -> dict:
observed = store.head(intent.key)
if observed.get("content_length") != observed.get("expected_length"):
raise ValueError("stored length does not match intent")
if observed.get("sha256") != intent.digest:
raise ValueError("stored digest does not match intent")
return {"player_id": intent.player_id, "purchase_id": intent.purchase_id,
"object_key": intent.key, "sha256": intent.digest, "audit_ready": True}
The example's 10 MiB limit is illustrative policy for this flow, not a claim about a provider. In production, calculate the digest while streaming, bind the expected length into the signed request, and reject a content type inferred only from a filename. A receipt needs its original bytes; an avatar can be decoded, resized, and scanned before publication. Keep those lifecycles separate.
I once treated a 200 OK from an upload endpoint as proof that a receipt was archived. The ledger later had an object key but no matching hash, and an audit export returned 404 because a cleanup job had used the avatar prefix. That was a naming bug, not a multipart bug. The fix was boring: distinct prefixes, an explicit reconciliation job, and an alert when an intent has no completed object after 15 minutes.
Keep it boring.
Where do access control and delivery simplicity pull apart?
Presigned URLs simplify delivery because the browser talks directly to storage, but they also turn the URL into a temporary bearer credential. Keep expirations short, bind method and content type, and never let a client choose a receipt key. On completion, authorize the player and purchase again; the callback can be replayed. Idempotency on (player_id, purchase_id, digest) prevents a double click from creating two audit rows.
For multipart, persist an upload ID and each accepted part's checksum. A scheduled reaper should abort intents that are incomplete after the policy window. Without that reaper, abandoned mobile uploads consume storage even though no receipt is visible. Single-request uploads avoid that state, which is why they remain the beginner default for small avatars.
Deletion needs an equally explicit rule. GDPR Article 17 describes erasure rights, while a fraud or purchase-retention policy may require keeping an original for a defined period. Record the legal basis and deadline in the ledger, then delete object data and indexes together when the deadline arrives. I'm not sure which retention period fits your jurisdiction; your counsel and records owner should resolve that before launch.
Rejected option and the rollout test
I rejected “multipart for every file.” It increases code paths, reconciliation work, and observability surface for a class of uploads that usually completes in one request. It is valid when receipts are large, networks are lossy, or resumability is a hard product requirement.
Roll out with a fixture set that includes a 12 KB avatar, a file exactly at the threshold, a file one byte over it, a duplicate purchase callback, a wrong media type, and an interrupted part upload. Run the set against a staging bucket whose lifecycle rules match production, then repeat it with a deliberately slow connection so the retry path gets exercised. Assert that the original receipt remains addressable, the avatar key cannot overwrite another player, and a failed finalization leaves no audit_ready row. Compare the intent ledger with object listings after the test and make the reconciliation report empty before enabling traffic. Log request IDs and hashes, never signed URLs or receipt contents.
Top comments (0)