Skip to main content

Conditional queries

Last update:

Conditional Requests in the S3 API allow you to perform operations only if certain conditions are met by using headers.You can use them:

  • perform read and write requests with a preliminary check of the object state;
  • manage updates and downloads of objects based on their current state or metadata;
  • conform to the familiar scenarios of working to S3 standards;
  • protect data from accidental overwriting;
  • optimize traffic costs.

Conditional queries can be used for different scenarios.

Headings

OperationSupported headers
PutObject
  • If-Match
  • If-None-Match
CopyObject
  • x-amz-copy-source-if-match
  • x-amz-copy-source-if-none-match
  • x-amz-copy-source-if-modified-since
  • x-amz-copy-source-if-unmodified-since
UploadPartCopy
  • x-amz-copy-source-if-match
  • x-amz-copy-source-if-none-match
  • x-amz-copy-source-if-modified-since
  • x-amz-copy-source-if-unmodified-since
DeleteObjectIf-Match
CompleteMultipartUpload
  • If-Match
  • If-None-Match

PutObject operations

CaptionConditional fulfillmentError on violation
If-MatchThe object is written if an active version exists and its ETag matches the value specified in the header412 Precondition Failed
If-None-MatchThe object is written if the key has no active version, including delete marker412 Precondition Failed

CopyObject and UploadPartCopy operations

CaptionConditional fulfillmentError on violation
x-amz-copy-source-if-matchThe object is copied if the ETag of the source object matches the value specified in the header412 Precondition Failed
x-amz-copy-source-if-none-matchThe object is copied if the ETag of the source object does not match the value specified in the header412 Precondition Failed
x-amz-copy-source-if-modified-sinceThe object is copied if the object is modified later than the date specified in the header412 Precondition Failed
x-amz-copy-source-if-unmodified-sinceThe object is copied if the object has not been modified after the date specified in the header412 Precondition Failed

DeleteObject operations

CaptionConditional fulfillmentError on violation
If-MatchThe object is deleted if an active version exists and its ETag matches the value specified in the header412 Precondition Failed

CompleteMultipartUpload operations

CaptionConditional fulfillmentError on violation
If-MatchSegmented loading is completed if the ETag of the object matches the value specified in the header412 Precondition Failed
If-None-MatchSegmented boot completion is performed if the object does not exist412 Precondition Failed

Error description

404 Not FoundObject not found (e.g. with If-Match header)
409 ConflictThe object was modified or deleted before the conditional operation was executed
412 Precondition FailedThe condition in the title is not met

Examples of use cases

  • update conflict protection — the object will be updated only if it has not changed since the last invocation ( If-Match header);
  • data synchronization — the object will be loaded only if it was changed after the specified time ( If-Modified-Since header);
  • read optimization — the object will be retrieved only if it does not match the local version ( If-None-Match header);
  • overwriting protection — the object will not be written by key if there is already another object with the same key ( If-None-Match header).