How do I store generated media under content-addressed (sha256) keys without overwriting or racing, using S3 or R2 conditional writes and checksums?
Problem. Deduplicating and verifying generated assets across retries (see Celery at-least-once finding). Conditions. Amazon S3 User Guide (conditional writes, checking object integrity) and Cloudflare R2 S3-compatibility docs (page updated Oct 14, 2026). Method. Name the object key after the content hash (for example outputs/sha256/ab/abcd...); upload with If-None-Match: * so the write succeeds only if the key does not exist (S3: header prevents overwrites by validating no object with that key; requires SigV4). R2 documents that conditional headers on PutObject are evaluated atomically at commit, and that with concurrent If-None-Match: * on an absent key at most one write succeeds and the others get 412 PreconditionFailed; treat 412 as 'already stored'. S3 can verify uploads with checksums; supported algorithms include SHA-256 (CRC64NVME is the default algorithm for S3 checksum calculation), so send the SHA-256 you computed and let the service reject corrupt uploads (S3-specific; th...
Structured fields
{
"citations": [
{
"url": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/conditional-writes.html",
"note": "How to prevent object overwrites; Conditional operations; algorithms list"
},
{
"url": "https://developers.cloudflare.com/r2/api/s3/api/index.md",
"note": "How to prevent object overwrites; Conditional operations; algorithms list"
},
{
"url": "https://docs.aws.amazon.com/AmazonS3/latest/userguide/checking-object-integrity.html",
"note": "How to prevent object overwrites; Conditional operations; algorithms list"
}
]
}Evidence claims
- [sourced_fact] Problem. Deduplicating and verifying generated assets across retries (see Celery at-least-once finding). Conditions. Amazon S3 User Guide (conditional writes, checking object integrity) and Cloudflare R2 S3-compatibility docs (page updated Oct 14, 2026). Method. Name the object key after the content hash (for example outputs/sha256/ab/abcd...); upload with If-None-Match: * so the write succeeds only if the key does not exist (S3: header prevents overwrites by validating no object with that key; requires SigV4). R2 documents that conditional headers on PutObject are evaluated atomically at commit, and that with concurrent If-None-Match: * on an absent key at most one write succeeds and the others get 412 PreconditionFailed; treat 412 as 'already stored'. S3 can verify uploads with checksums; supported algorithms include SHA-256 (CRC64NVME is the default algorithm for S3 checksum calculation), so send the SHA-256 you computed and let the service reject corrupt uploads (S3-specific; the R2 table shows checksum feature support per operation, not read in full). Keep the sidecar (prompt JSON, workflow, model hashes, ComfyUI commit; see C3-B574-09/10) as a second object keyed by the same hash plus a manifest key per job id (design inference). Failure modes. Hash computed on a re-encoded copy differs from the stored bytes; 412 treated as an error and retried forever; metadata mutable after upload when stored as object metadata. Limitations. Prices omitted. A content hash identifies bytes, not the semantic output of a pipeline; non-deterministic GPUs give different hashes for the same workflow. Version and date. AWS docs undated; R2 page updated Oct 14, 2026. · locator: How to prevent object overwrites; Conditional operations; algorithms list source
Rights
| component | license | hosting | redistribution | modification | training | Evidence and notes |
|---|---|---|---|---|---|---|
| documentation | unknown | permitted | permitted | unknown | unknown | Applies to this original summary only, not to the cited sources. |