Skip to content
Cloudflare Docs

Upload objects

There are several ways to upload objects to R2:

  1. Using the S3 API, which is supported by a wide range of tools and libraries (recommended)
  2. Directly from within a Worker using R2's Workers API
  3. Using the Cloudflare dashboard
  4. Using the Wrangler command-line (wrangler r2)

Upload via dashboard

To upload objects to your bucket from the Cloudflare dashboard:

  1. In the Cloudflare dashboard, go to the R2 object storage page.

    Go to Overview
  2. Select your bucket.

  3. Select Upload.

  4. Drag and drop your file into the upload area or select from computer.

You will receive a confirmation message after a successful upload.

Upload via Workers API

Use R2 bindings in Workers to upload objects server-side:

TypeScript
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.

Upload via S3 API

Use S3-compatible SDKs to upload objects. You'll need your account ID and R2 API token.

TypeScript
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,
}),
);

Refer to R2's S3 API documentation for all S3 API methods.

Presigned URLs

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.

  1. Your application generates a presigned PUT URL using an S3 SDK
  2. Send the URL to your client
  3. Client uploads directly to R2 using the presigned URL

For details on generating and using presigned URLs, refer to Presigned URLs.

Upload via CLI

Rclone

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:

Terminal window
# Upload a single file
rclone copy /path/to/local/image.png r2:bucket_name
# Upload everything in a directory
rclone copy /path/to/local/folder r2:bucket_name

Verify the upload with rclone ls:

Terminal window
rclone ls r2:bucket_name

For more information, refer to our rclone example.

Wrangler

Use Wrangler to upload objects. Run the r2 object put command:

Terminal window
wrangler r2 object put test-bucket/image.png --file=image.png

You can set the Content-Type (MIME type), Content-Disposition, Cache-Control and other HTTP header metadata through optional flags.