Features
- S3-compatible API for easy migration
- Zero egress fees for data retrieval
- Automatic global distribution via Cloudflare CDN
- Native Workers binding for edge access
Pros
- Zero egress fees eliminate surprise costs
- S3 API compatibility means easy migration
- Integrated with Cloudflare's edge network
Cons
- Fewer storage classes than AWS S3
- Less mature than established object stores
- Some S3 features are not yet supported
Overview
Cloudflare R2 is an S3-compatible object storage service with a game-changing pricing model: zero egress fees. While AWS S3 and other object storage services charge for data retrieved from storage (often the largest cost component), R2 charges only for storage and operations, making costs dramatically more predictable.
R2 provides an S3-compatible API, meaning existing tools, libraries, and applications that work with S3 can switch to R2 with minimal code changes. This includes the AWS SDK, rclone, and other S3-compatible tools.
R2 integrates natively with Cloudflare Workers, allowing edge functions to read and write objects directly. Combined with Cloudflare’s CDN, stored objects can be served globally with low latency through custom domains.
When to Use
Choose Cloudflare R2 when egress costs are a concern, which is most applications that serve files to users (images, videos, downloads). It is the best option for S3-compatible storage without egress fees.
Getting Started
// In a Cloudflare Worker
export default {
async fetch(request: Request, env: Env) {
const object = await env.MY_BUCKET.get('image.png')
if (!object) return new Response('Not found', { status: 404 })
return new Response(object.body, {
headers: { 'content-type': object.httpMetadata?.contentType ?? '' }
})
}
}