Cloudflare R2 is an S3-compatible object storage service that eliminates egress fees entirely. It provides the same API as AWS S3, so existing S3-compatible tools and libraries work without modification. R2 is ideal for applications serving large amounts of data where egress costs would otherwise dominate the storage bill.
Store and serve images, videos, and documents with zero egress costs, regardless of how many times assets are downloaded by end users.
Store application backups and archival data with S3-compatible tools while paying only for storage, not retrieval.
Use R2 as the origin for Cloudflare CDN to serve static assets globally with automatic cache invalidation and no bandwidth charges.
import { S3Client, PutObjectCommand, GetObjectCommand } from "@aws-sdk/client-s3";const r2 = new S3Client({region: "auto",endpoint: `https://${process.env.R2_ACCOUNT_ID}.r2.cloudflarestorage.com`,credentials: {accessKeyId: process.env.R2_ACCESS_KEY_ID!,secretAccessKey: process.env.R2_SECRET_ACCESS_KEY!,},});export async function uploadFile(bucket: string, key: string, body: Buffer) {await r2.send(new PutObjectCommand({ Bucket: bucket, Key: key, Body: body }));return { bucket, key, url: `https://${bucket}.r2.dev/${key}` };}
Seamless integration, great documentation. Set up in under 10 minutes.
2 days ago
Works well for our use case. Would love to see more webhook event types.
1 week ago
Excellent compliance coverage. HIPAA audit trail works perfectly.
2 weeks ago
| Key | Description | Example |
|---|---|---|
| R2_ACCOUNT_ID | Your Cloudflare account ID | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| R2_ACCESS_KEY_ID | R2 API access key ID | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
| R2_SECRET_ACCESS_KEY | R2 API secret access key | xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx |
Cloudflare R2 is an S3-compatible object storage service with the unique advantage of zero egress fees. It uses the standard S3 API, so existing tools and code work without changes. R2 is the best storage choice for applications with high read volumes where AWS S3 egress costs would be prohibitive.