Skip to main content

Overview

Cloudflare R2 Storage provides object storage without egress fees. Store large amounts of unstructured data with S3-compatible APIs.

Bucket Management

Create a Bucket

Create a new R2 bucket:
Options:
  • <name> - Bucket name (3-63 characters, lowercase, numbers, hyphens)
  • --location <hint> - Geographic placement hint
    • weur - Western Europe
    • eeur - Eastern Europe
    • apac - Asia Pacific
    • oc - Oceania
    • wnam - Western North America
    • enam - Eastern North America
  • --storage-class, -s - Default storage class for uploads
  • --jurisdiction, -J - Data residency jurisdiction (e.g., eu, fedramp)
  • --update-config - Automatically add to wrangler.json
  • --name <binding> - Custom binding name
Examples:
Configuration:
wrangler.json

List Buckets

View all R2 buckets in your account:
Example Output:

Get Bucket Info

Retrieve detailed information about a bucket:
Options:
  • <bucket> - Bucket name
  • --jurisdiction, -J - Bucket jurisdiction
  • --json - Output as JSON
Example:
Output:

Update Bucket

Update the default storage class of a bucket:
Options:
  • <name> - Bucket name
  • --storage-class, -s - New default storage class (required)
  • --jurisdiction, -J - Bucket jurisdiction
Example:

Delete a Bucket

Delete an empty R2 bucket:
The bucket must be empty before deletion. Delete all objects first.

Object Operations

Put an Object

Upload a file to R2:
Options:
  • <bucket>/<key> - Destination path (format: bucket/key)
  • --file, -f - Local file to upload
  • --pipe, -p - Read from stdin instead of file
  • --content-type, --ct - MIME type
  • --content-disposition, --cd - Presentational info
  • --content-encoding, --ce - Encoding applied to object
  • --content-language, --cl - Content language
  • --cache-control, --cc - Caching behavior
  • --expires - Expiration date/time
  • --storage-class, -s - Storage class for this object
  • --jurisdiction, -J - Bucket jurisdiction
  • --local - Upload to local R2 simulation
  • --persist-to - Local persistence directory
Examples:

Bulk Operations

Bulk Upload (Experimental)

Upload multiple files efficiently:
Options:
  • <bucket> - Target bucket name
  • --filename, -f - JSON file with key/file mappings
  • --concurrency - Concurrent uploads (default: 20)
  • All standard put options (content-type, cache-control, etc.)
Mapping File Format:
Example:

Advanced Features

CORS Configuration

Configure Cross-Origin Resource Sharing:
View CORS rules:
Delete CORS rules:

Custom Domains

Connect a custom domain to your bucket:
List domains:
Remove domain:

Lifecycle Rules

Manage object lifecycle:
View lifecycle:
Delete lifecycle:

Object Locking

Enable WORM (Write Once Read Many):
Get lock status:

Worker Integration

Access R2 from your Worker:

Local Development

Test R2 operations locally:
Local R2 data is stored in .wrangler/state/v3/r2/ by default.

Storage Classes

R2 offers different storage classes for cost optimization:
  • Standard - Default, frequent access, lowest latency
  • InfrequentAccess - Less frequent access, lower storage cost
Set storage class during upload or as bucket default.

Best Practices

Naming

  • Use lowercase, numbers, and hyphens
  • Bucket names: 3-63 characters
  • Avoid dots for SSL/TLS compatibility
  • Use meaningful, descriptive names

Performance

  • Use appropriate storage classes
  • Enable caching with Cache-Control headers
  • Consider custom domains for production
  • Use bulk operations for multiple files

Organization

  • Use prefixes to organize objects: images/, videos/
  • Implement consistent naming conventions
  • Use metadata for searchability
  • Plan key structure before scaling

Security

  • Use jurisdictions for compliance
  • Configure CORS when needed
  • Implement access controls in Workers
  • Use presigned URLs for temporary access

Limits and Quotas

  • Max object size: 5 TB (via multipart upload)
  • Max put size: 300 MB (single request)
  • Bucket name: 3-63 characters
  • No egress fees: Unlimited data transfer out