Upload objects
There are several ways to upload objects to R2:
- Using the S3 API, which is supported by a wide range of tools and libraries (recommended)
- Directly from within a Worker using R2's Workers API
- Using the Cloudflare dashboard ↗
- Using the Wrangler command-line (
wrangler r2)
To upload objects to your bucket from the Cloudflare dashboard:
-
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview -
Select your bucket.
-
Select Upload.
-
Drag and drop your file into the upload area or select from computer.
You will receive a confirmation message after a successful upload.
Use R2 bindings in Workers to upload objects server-side:
export default { async fetch(request: Request, env: Env, ctx: ExecutionContext) { await env.MY_BUCKET.put("image.png", request.body); return new Response("Uploaded"); },} satisfies ExportedHandler<Env>;For complete documentation, refer to Workers API.
Use S3-compatible SDKs to upload objects. You'll need your account ID and R2 API token.
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
const S3 = new S3Client({ region: "auto", // Required by SDK but not used by R2 // Provide your Cloudflare account ID endpoint: `https://<ACCOUNT_ID>.r2.cloudflarestorage.com`, // Retrieve your S3 API credentials for your R2 bucket via API tokens (see: https://developers.cloudflare.com/r2/api/tokens) credentials: { accessKeyId: '<ACCESS_KEY_ID>', secretAccessKey: '<SECRET_ACCESS_KEY>', },});
await S3.send( new PutObjectCommand({ Bucket: "my-bucket", Key: "image.png", Body: fileContent, }),);import boto3
s3 = boto3.client( service_name="s3", # Provide your Cloudflare account ID endpoint_url=f"https://{ACCOUNT_ID}.r2.cloudflarestorage.com", # Retrieve your S3 API credentials for your R2 bucket via API tokens (see: https://developers.cloudflare.com/r2/api/tokens) aws_access_key_id=ACCESS_KEY_ID, aws_secret_access_key=SECRET_ACCESS_KEY, region_name="auto", # Required by SDK but not used by R2)
s3.put_object(Bucket="my-bucket", Key="image.png", Body=file_content)Refer to R2's S3 API documentation for all S3 API methods.
For client-side uploads where users upload directly to R2, use presigned URLs. Your server generates a temporary upload URL that clients can use without exposing your API credentials.
- Your application generates a presigned PUT URL using an S3 SDK
- Send the URL to your client
- Client uploads directly to R2 using the presigned URL
For details on generating and using presigned URLs, refer to Presigned URLs.
Rclone ↗ is a command-line tool for managing files on cloud storage. Rclone works well for uploading multiple files from your local machine or copying data from other cloud storage providers.
To use rclone, install it onto your machine using their official documentation - Install rclone ↗.
Upload files with the rclone copy command:
# Upload a single filerclone copy /path/to/local/image.png r2:bucket_name
# Upload everything in a directoryrclone copy /path/to/local/folder r2:bucket_nameVerify the upload with rclone ls:
rclone ls r2:bucket_nameFor more information, refer to our rclone example.
Use Wrangler to upload objects. Run the r2 object put command:
wrangler r2 object put test-bucket/image.png --file=image.pngYou can set the Content-Type (MIME type), Content-Disposition, Cache-Control and other HTTP header metadata through optional flags.
Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark
-