Download objects
You can download objects from R2 using the dashboard, Workers API, S3 API, or command-line tools.
-
In the Cloudflare dashboard, go to the R2 object storage page.
Go to Overview -
Select your bucket.
-
Locate the object you want to download.
-
Select ... for the object and click Download.
Use R2 bindings in Workers to download objects:
export default { async fetch(request: Request, env: Env, ctx: ExecutionContext) { const object = await env.MY_BUCKET.get("image.png"); return new Response(object.body); },} satisfies ExportedHandler<Env>;For complete documentation, refer to Workers API.
Use S3-compatible SDKs to download objects. You'll need your account ID and R2 API token.
import { S3Client, GetObjectCommand } 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>', },});
const response = await S3.send( new GetObjectCommand({ Bucket: "my-bucket", Key: "image.png", }),);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)
response = s3.get_object(Bucket="my-bucket", Key="image.png")image_data = response["Body"].read()Refer to R2's S3 API documentation for all S3 API methods.
For client-side downloads where users download directly from R2, use presigned URLs. Your server generates a temporary download URL that clients can use without exposing your API credentials.
- Your application generates a presigned GET URL using an S3 SDK
- Send the URL to your client
- Client downloads directly from R2 using the presigned URL
For details on generating and using presigned URLs, refer to Presigned URLs.
Use Wrangler to download objects. Run the r2 object get command:
wrangler r2 object get test-bucket/image.pngThe file will be downloaded into the current working directory. You can also use the --file flag to set a new name for the object as it is downloaded, and the --pipe flag to pipe the download to standard output (stdout).
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
-