Cloudflare
R3 S3 API

πŸ“¦ Cloudflare R2 – Using the S3-Compatible API

This guide shows how to configure and upload files to Cloudflare R2 using the AWS CLI and S3-compatible API.


πŸ” 1. Configure AWS CLI for Cloudflare R2

Use the following command to set up a new AWS CLI profile for R2:

aws configure --profile r2

Provide the following when prompted:

  • Access Key: (Get this from R2 β†’ Manage API Tokens)
  • Secret Key: (Also from the same place)
  • Region: auto or any valid AWS region like us-east-1
  • Output format: json (or your preferred format)

πŸ“€ 2. Upload a single file to R2

aws s3 --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com \
  cp myfile.txt s3://my-r2-bucket/ --profile r2

βœ… Replace:

  • <ACCOUNT_ID> with your actual Cloudflare Account ID
  • myfile.txt with your local file name
  • my-r2-bucket with your R2 bucket name

πŸ“‚ 3. Upload all files in current folder to R2

To recursively upload everything in the current directory:

aws s3 sync . s3://my-r2-bucket \
  --endpoint-url https://<ACCOUNT_ID>.r2.cloudflarestorage.com \
  --profile r2

This command:

  • Recursively uploads files from the current folder
  • Skips files that haven't changed (based on timestamp and size)

πŸ“ Notes

  • R2 is S3-compatible, so standard S3 tools and SDKs will work.
  • Zero egress fees β€” great for serving content publicly.
  • You can also use tools like s3cmd, rclone, or SDKs like boto3 for programmatic access.


πŸ§™ AI Wizard - Instant Page Insights

Click the button below to analyze this page.
Get an AI-generated summary and key insights in seconds.
Powered by Perplexity AI!