Thanks to visit codestin.com
Credit goes to github.com

Skip to content

S3 Conditional Operations

chrislusf edited this page Aug 23, 2025 · 1 revision

S3 Conditional Operations

SeaweedFS supports AWS S3-compatible conditional headers for safe concurrent access patterns, optimistic locking, and efficient conditional operations.

Supported Conditional Headers

Header Applies To Condition Use Case
If-Match GET, PUT, COPY ETag matches Ensure object hasn't changed
If-None-Match GET, PUT, COPY ETag doesn't match Prevent overwrites, caching
If-Modified-Since GET, COPY Modified after date Conditional downloads
If-Unmodified-Since GET, PUT, COPY Not modified after date Safe modifications

HTTP Examples

Conditional GET (Caching)

# First, get the object and note its ETag
curl -I "http://localhost:8333/mybucket/myfile.txt"
# Response: ETag: "d41d8cd98f00b204e9800998ecf8427e"

# Conditional GET - only download if object changed
curl -H "If-None-Match: \"d41d8cd98f00b204e9800998ecf8427e\"" \
  "http://localhost:8333/mybucket/myfile.txt"

Conditional PUT (Optimistic Locking)

# Safe update - only modify if object hasn't changed
curl -X PUT -H "If-Match: \"d41d8cd98f00b204e9800998ecf8427e\"" \
  -H "Content-Type: text/plain" \
  --data "Updated content" \
  "http://localhost:8333/mybucket/myfile.txt"

# Prevent overwrites - only create if object doesn't exist
curl -X PUT -H "If-None-Match: *" \
  -H "Content-Type: text/plain" \
  --data "New file content" \
  "http://localhost:8333/mybucket/newfile.txt"

If-Modified-Since

# Only download if modified after specific date
curl -H "If-Modified-Since: Wed, 15 Jan 2024 10:00:00 GMT" \
  "http://localhost:8333/mybucket/log-file.txt"

If-Unmodified-Since

# Update only if not modified since last read
curl -X PUT \
  -H "If-Unmodified-Since: Wed, 15 Jan 2024 10:00:00 GMT" \
  -H "Content-Type: text/plain" \
  --data "Updated content" \
  "http://localhost:8333/mybucket/document.txt"

Copy Operations

# Copy only if source object hasn't changed
curl -X PUT \
  -H "x-amz-copy-source: /source-bucket/source-file.txt" \
  -H "x-amz-copy-source-if-match: \"source-etag\"" \
  "http://localhost:8333/dest-bucket/dest-file.txt"

HTTP Status Codes

Status Code Condition Meaning
200 OK Condition met Operation succeeded
304 Not Modified If-None-Match matched Object unchanged (GET only)
412 Precondition Failed Condition not met Operation blocked by condition

Related Documentation

Introduction

API

Configuration

Filer

Management

Advanced Filer Configurations

Cloud Drive

AWS S3 API

S3 Authentication & IAM

Server-Side Encryption

S3 Client Tools

Machine Learning

HDFS

Replication and Backup

Metadata Change Events

Messaging

Use Cases

Operations

Advanced

Security

Misc Use Case Examples

Clone this wiki locally