S3 API Compatibility: Conditional Operations, Consistency, and Multipart Upload
How Cloudflare R2's S3-compatible API handles conditional writes, read consistency, multipart limits, errors, billing, and observability.
This page summarizes Cloudflare R2 documentation on the S3-compatible API: which operations are supported, how conditional headers behave at commit time, what strong reads do and do not guarantee, multipart upload rules, common HTTP errors, and how failed requests are billed. It is aimed at teams porting AWS S3 SDKs or backup tools to R2 who need predictable concurrency semantics and fewer surprise 412 or multipart failures.
S3 API compatibility: what R2 implements and what it omits
Section titled “S3 API compatibility: what R2 implements and what it omits”R2 exposes an S3-style HTTP API documented in the S3 API compatibility tables. Each operation lists implemented features (✅), experimental ones (🚧), and gaps (❌). Bucket-level coverage includes ListBuckets, CreateBucket, PutBucketCors, lifecycle and encryption configuration, while many AWS-only APIs (ACLs, bucket policies, replication, object lock, analytics configurations) are unimplemented. Object-level coverage includes GetObject, PutObject, HeadObject, listing, delete, CopyObject, and the full multipart sequence.
This page has two sections: bucket-level operations and object-level operations. Each section will have two tables: a table of implemented APIs and a table of unimplemented APIs.
— Cloudflare, S3 API compatibility
R2 also documents S3 extensions (extra headers and behaviors beyond strict AWS parity), presigned URLs, temporary credentials, and SDK examples for common AWS client libraries. For signing problems, troubleshooting suggests reproducing the request with curl and comparing against the signing examples.
ListObjects vs ListObjectsV2 when listing bucket keys
Section titled “ListObjects vs ListObjectsV2 when listing bucket keys”ListObjects remains supported, but R2 recommends ListObjectsV2 for new application code. The compatibility page notes that even supported APIs may omit AWS-only parameters such as x-amz-request-payer or x-amz-expected-bucket-owner.
Storage classes and encryption on PutObject
Section titled “Storage classes and encryption on PutObject”PutObject and multipart create support STANDARD and STANDARD_IA via x-amz-storage-class. Server-side encryption with AWS KMS is not implemented; customer-provided keys (SSE-C) are supported on several read/write/copy paths per the feature tables.
Conditional operations on PutObject: create-once and optimistic locking
Section titled “Conditional operations on PutObject: create-once and optimistic locking”PutObject accepts the standard S3 conditional headers If-Match, If-None-Match, If-Modified-Since, and If-Unmodified-Since. The wildcard form If-None-Match: * is the usual pattern for “only write if the key does not exist yet.”
PutObject supports the standard S3 conditional headers If-Match, If-None-Match, If-Modified-Since, and If-Unmodified-Since. If-None-Match: * in particular is commonly used to implement “create-once” semantics: the write only succeeds if the key does not exist yet.
— Cloudflare, Conditional operations in PutObject
R2 evaluates these conditions atomically as part of the same commit that writes the object—not against an older snapshot. Competing conditional writes to the same key are serialized.
When two or more clients concurrently issue PutObject with If-None-Match: * for a previously absent key, at most one request succeeds and every other request fails with a 412 PreconditionFailed error. It is therefore safe to rely on If-None-Match: * for “create-once” semantics: two concurrent conditional writes can never both observe success.
— Cloudflare, Consistency model
The same semantics are summarized under Behaviors & Limitations on the compatibility page. Conditional headers on CreateMultipartUpload can also yield HTTP 412 when the object already exists and the condition fails (release notes).
HTTP 412 PreconditionFailed when ETag or time does not match
Section titled “HTTP 412 PreconditionFailed when ETag or time does not match”When a condition fails, R2 returns S3 code PreconditionFailed (HTTP 412, R2 error code 10031):
Conditional headers (If-Match, If-Unmodified-Since, etc.) were not satisfied. Object’s ETag or modification time does not match your condition. Refetch and retry.
— Cloudflare, Error codes
Per pricing, a PutObject that fails with 412 after successful authentication still counts as a Class A operation—you pay for the attempt even though nothing changed.
Consistency model: strong reads, negative reads, and in-flight writes
Section titled “Consistency model: strong reads, negative reads, and in-flight writes”R2 describes read/write interaction in the consistency model. Conditional writes are strongly consistent at commit. For reads, HeadObject and GetObject are strongly consistent in the sense that they reflect committed bucket state at processing time—they are not stale.
Why NoSuchKey (404) does not prove a lost PutObject failed
Section titled “Why NoSuchKey (404) does not prove a lost PutObject failed”A common mistake is to GetObject after a timed-out PutObject and treat NoSuchKey as proof the upload failed:
A strongly consistent read (HeadObject or GetObject) that returns NoSuchKey (404) tells you that the object did not exist at the moment the read was processed. This absence is not final with respect to an earlier PutObject whose outcome is still unknown: a request that was still in flight — for example, a client that lost its connection before receiving the response — may still commit after the negative read has returned.
— Cloudflare, Consistency model
Practical approach: wait until the original write returns a definitive success or error before trusting a negative read. Alternatively, retry with If-None-Match: *; if the ambiguous write actually committed, the retry fails with 412 PreconditionFailed.
CopyObject conditionals: source headers vs destination (cf-copy-destination-if-*)
Section titled “CopyObject conditionals: source headers vs destination (cf-copy-destination-if-*)”CopyObject supports standard x-amz-copy-source-if-* headers on the source object. R2 adds destination-side conditionals documented under Conditional operations in CopyObject for the destination object:
cf-copy-destination-if-matchcf-copy-destination-if-none-matchcf-copy-destination-if-modified-sincecf-copy-destination-if-unmodified-since
These mirror PutObject conditionals on the target key. If the destination state does not match, the copy is rejected with 412 PreconditionFailed. This feature is marked beta in the extensions doc; feedback channels are listed there.
Non-atomic timing between source and destination checks
Section titled “Non-atomic timing between source and destination checks”Source and destination conditions are checked at different moments:
The x-amz-copy-source-if-… headers are guaranteed to be checked when the source object for the copy operation is selected, and the cf-copy-destination-if-… headers are guaranteed to be checked when the object is committed to the bucket state. However, the time at which the source object is selected for copying, and the point in time when the destination object is committed to the bucket state are not necessarily the same.
— Cloudflare, Non-atomicity relative to x-amz-copy-source-if
You cannot treat a single CopyObject with both source and destination conditionals as one atomic transaction across both objects. Design workflows that re-fetch ETags or use idempotent keys if the source might change between selection and commit.
Multipart upload: part sizes, completion rules, and typical errors
Section titled “Multipart upload: part sizes, completion rules, and typical errors”Object upload guidance lives under Upload objects and Manage objects. Multipart limits:
| Rule | Value |
|---|---|
| Minimum part size (except last) | 5 MiB |
| Maximum part size | 5 GiB |
| Maximum parts | 10,000 |
| Non-trailing part sizes | Must be identical |
R2 enforces uniform non-final part sizes at CompleteMultipartUpload (release notes); mismatches yield errors such as InvalidPart (10048) per Error codes. Uploading below 5 MiB on a non-terminal part returns EntityTooSmall (10011).
ETags: each part’s ETag is the MD5 of that part’s bytes. The completed object ETag is the MD5 of the concatenated binary MD5 sums of all parts, a hyphen, and the part count (example in Upload objects).
Incomplete uploads: by default aborted after 7 days; configurable via lifecycle (Upload objects). Wrong or expired uploadId → NoSuchUpload (10024).
UploadPart behavior: uploading the same part number replaces the prior part; if a replacement upload fails, the original part is lost and must be re-uploaded (S3 API compatibility).
Upload and digest errors during PUT and multipart
Section titled “Upload and digest errors during PUT and multipart”| R2 code | HTTP | Typical cause |
|---|---|---|
10033 |
411 | Missing Content-Length on PUT/POST |
10013 |
400 | Body shorter than Content-Length |
10014 / 10037 |
400 | Malformed or mismatched checksum headers |
10039 |
416 | Invalid Range on read |
Details and fixes are in Error codes.
ListBuckets extensions when you have more than 1,000 buckets
Section titled “ListBuckets extensions when you have more than 1,000 buckets”Standard ListBuckets may not expose all pagination knobs in every S3 library. R2 accepts the same search parameters as ListObjectsV2, including via HTTP headers that override query parameters (ListBuckets extensions):
| Search parameter | HTTP header |
|---|---|
prefix |
cf-prefix |
start-after |
cf-start-after |
continuation-token |
cf-continuation-token |
max-keys |
cf-max-keys (default and max 1000) |
Response pagination may also appear in headers such as cf-is-truncated and cf-next-continuation-token when XML fields are hard to read from your client.
Observability: data access logs, metrics, and event notifications
Section titled “Observability: data access logs, metrics, and event notifications”Data Access Logs (data access logs) record successful object API activity: reads (GetObject, HeadObject), writes/copies, list operations, multipart steps, and deletes. They do not include bucket configuration APIs or failed requests with HTTP status ≥ 400.
Metrics and analytics (metrics and analytics) expose an operations dataset with actionType, actionStatus (success, userError, internalError), bucketName, objectName, responseStatusCode, and datetime. Jurisdiction-prefixed bucket names apply where relevant (e.g. eu_your-bucket-name).
Event notifications (event notifications) fire object-create on PutObject, CopyObject, and CompleteMultipartUpload, and object-delete on explicit delete and lifecycle deletion.
Use logs for audit trails, metrics for volume and error rates, and notifications for downstream pipelines—not as a substitute for application-level verification of conditional writes.
Operation classes and billing for failed S3 requests
Section titled “Operation classes and billing for failed S3 requests”R2 pricing splits operations into Class A (mutations and listings), Class B (reads and many bucket GETs), and free operations (DeleteObject, DeleteBucket, AbortMultipartUpload).
Authentication and authorization failures (401, signature-related 403, permission 403) are not charged. After auth succeeds, many failures are billed by class—for example PutObject with 412 or 400 BadDigest counts as Class A. Plan retries and conditional checks accordingly.
Temporary credentials narrow allowed S3 actions via an actions list; explicit actions override broad scopes. Narrow tokens reduce blast radius when embedding credentials in workers or edge code.
Common mistakes when using R2 as an S3 endpoint
Section titled “Common mistakes when using R2 as an S3 endpoint”- Treating
NoSuchKeyafter a timeout as proof thatPutObjectfailed, without waiting for a definitive write response or usingIf-None-Match: *on retry. - Assuming
CopyObjectwith both source and destination conditionals is one atomic check across two objects. - Using different sizes for non-final multipart parts, or parts under 5 MiB except the last.
- Completing multipart uploads with wrong part ETags after
UploadPartreplacement failures. - Expecting Data Access Logs to include
412/400failures—they omit HTTP ≥ 400 responses. - Relying on unimplemented S3 features (object lock, bucket policy, tagging APIs) without checking the compatibility tables.
How to check this on your site
Section titled “How to check this on your site”-
Call
HeadObjectorGetObjectwithIf-Match/If-None-Matchagainst a test key and confirm412when the ETag disagrees, using the patterns in Conditional operations in PutObject. -
Run two concurrent
PutObjectrequests withIf-None-Match: *on a new key and verify exactly one succeeds and the other returns412, matching Consistency model behavior. -
Complete a multipart upload with equal-sized interior parts (≥ 5 MiB) and confirm
CompleteMultipartUploadsucceeds; retry with unequal interior sizes and map the response to Error codes. -
Enable Data Access Logs and metrics, perform a successful
PutObject, and confirm the operation appears withactionStatusand status code fields. -
You can check automatically in Answerwell (our tool): https://answerwell.org/workspace
Report an error or ask a question
Section titled “Report an error or ask a question”If something on this page does not match your experience or the linked Cloudflare docs, email yimasynthetic@gmail.com with the page URL and the exact statement you are questioning so it can be corrected or clarified.