R2
Store any file in the cloud and pay nothing to read it back out.
What is R2?
R2 is object storage (object storage = a service for keeping large files like images, videos, backups, and datasets). You upload files, get them back by name, and never worry about running a disk yourself.
Each file you store is called an object, and objects live inside a bucket (a bucket = a named folder-like container that holds your objects). R2 also speaks the same API as Amazon S3, the most popular object storage in the world, so existing S3 tools and code work with very few changes.
Think of it like…
A giant self-storage warehouse. You rent space by how much you store, but unlike other warehouses, taking your boxes out to look at them is completely free — that is the famous 'zero egress' part.
Why use R2?
Traditional cloud storage charges an 'egress fee' (egress = the cost of moving data OUT of the cloud to your users). For a popular site or app, that surprise bill can be larger than the storage itself. R2 removes it entirely.
No egress fees
Reading your files out to the internet costs $0, no matter how much traffic you serve.
Works with S3 tools
Point existing S3 SDKs, CLIs, and apps at R2 with almost no code changes.
Global by default
Files are served from Cloudflare's worldwide network, close to your users.
Pairs with Workers
Read and write objects directly from Workers code via a simple binding.
When should you use it?
User uploads & media
Profile photos, product images, PDFs, and video files for a website or app.
Backups & archives
Database dumps and logs you rarely change but want to keep safely and cheaply.
High-traffic downloads
Software releases, datasets, or podcast episodes downloaded by many people — where egress fees would normally hurt.
Data lakes
Store raw analytics and big-data files for later processing (this is where Pipelines feeds data in).
How do you start?
Wrangler is Cloudflare's command-line tool (a CLI = a program you type commands into in your terminal). The steps below create a bucket, connect it to a Worker, and read/write an object.
Install Wrangler & log in
Install the tool, then log in to your Cloudflare account in the browser window it opens.
npm install -g wrangler wrangler loginCreate a bucket
Bucket names use lowercase letters, numbers, and hyphens, 3-63 characters long.
wrangler r2 bucket create my-app-files wrangler r2 bucket listBind the bucket to your Worker
A binding gives your code a variable (here MY_BUCKET) to reach the bucket. Add this to wrangler.jsonc.
{ "r2_buckets": [ { "binding": "MY_BUCKET", "bucket_name": "my-app-files" } ] }Read & write objects from code
A PUT request stores the body as an object; any other request reads it back by name.
export default { async fetch(request, env) { const key = new URL(request.url).pathname.slice(1); if (request.method === "PUT") { await env.MY_BUCKET.put(key, request.body); return new Response(`Uploaded ${key}!`); } const object = await env.MY_BUCKET.get(key); if (object === null) { return new Response("Object Not Found", { status: 404 }); } return new Response(object.body); }, };Deploy
Publish your Worker to Cloudflare's global network.
wrangler deploy
Key concepts
Object
A single stored file plus its metadata, found by a unique key (its name/path).
Bucket
A named container that holds many objects, like a top-level folder.
Class A vs Class B
Class A = writes/lists ($4.50/million); Class B = reads ($0.36/million). Egress is still free.
S3 compatibility
R2 accepts the same requests as Amazon S3, so S3 SDKs and migration tools just work.
Tips & pricing
The free tier is generous
Every month you get 10 GB of storage, 1 million Class A operations, and 10 million Class B operations free — plenty for learning and small projects.
- Storage is billed at $0.015 per GB-month; you only pay for what you store.
- Egress (serving files to the internet) is always $0 — this is R2's headline feature.
- Use clear key prefixes like uploads/2026/photo.jpg to organize objects like folders.
- Connect a custom domain to a bucket to serve files publicly with no Worker required.
Related products
menu_bookOfficial docsopen_in_new