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:<name>- Bucket name (3-63 characters, lowercase, numbers, hyphens)--location <hint>- Geographic placement hintweur- Western Europeeeur- Eastern Europeapac- Asia Pacificoc- Oceaniawnam- Western North Americaenam- 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
wrangler.json
List Buckets
View all R2 buckets in your account:Get Bucket Info
Retrieve detailed information about a bucket:<bucket>- Bucket name--jurisdiction, -J- Bucket jurisdiction--json- Output as JSON
Update Bucket
Update the default storage class of a bucket:<name>- Bucket name--storage-class, -s- New default storage class (required)--jurisdiction, -J- Bucket jurisdiction
Delete a Bucket
Delete an empty R2 bucket:Object Operations
- Upload
- Download
- Delete
Put an Object
Upload a file to R2:<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
Bulk Operations
Bulk Upload (Experimental)
Upload multiple files efficiently:<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.)
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:.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
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
Related Commands
- KV Storage - Key-value storage
- D1 Database - SQL database
- Durable Objects - Stateful objects