Cloudflare R2 Basics
Why files need object storage and how Cloudflare R2 works

Buzz presents
pictures and files need a safe little home, and Cloudflare R2 is a great one. lets see how object storage works!pictures and files need a safe little home, and Cloudflare R2 is a great one. lets see how object storage works!

Your app is probably gonna need to store files. Profile pictures. Document uploads. Video content. So where do those files actually LIVE? That's the job of a file storage service.
Why You Can't Just Store Files on Your Server#
When you deploy an app to a service like Railway or Vercel, it's super tempting to think "I'll just save uploaded files to the server." Here's why that falls flat.
There's more wrong with keeping files on your server, too.
- Limited space. Servers have small hard drives
- Slow to serve. Sending big files from your server is slow
- Expensive. Server storage costs more than dedicated file storage
- No backups. If something goes wrong, the files are lost
So instead we use dedicated file storage services. They're built specifically to hold files reliably and serve them fast.
What Is Object Storage?#
File storage services use something called "object storage." Sounds fancy, but it's a pretty simple idea.
- Each file is an "object"
- Objects live in "buckets" (like folders)
- Each object has a unique name, called a key, and public objects get a URL
- You can make objects public or private
Picture a giant online filing cabinet. You put files in and you get URLs back. Then your app uses those URLs to show images, download documents, or stream videos.
Enter Cloudflare R2#

Cloudflare R2 is a file storage service, and here's what it brings to the table.
- Affordable. Much cheaper than Amazon S3
- Fast. Uses Cloudflare's global network
- Simple. Easy to set up and use
- S3-compatible. Works with existing tools
How R2 Works#
Let's walk through what happens when a user uploads a profile picture.
Step 1. User Selects a File#
The user clicks "upload" and picks an image from their computer.
Step 2. Your App Uploads to R2#
Your app sends the file over to Cloudflare R2 with a name (the key). R2 stores it safely, and the file's URL is built from that key.
Step 3. Save the URL#
You save the file's URL to your database, tied to the user's profile.
Step 4. Display the Image#
When someone views the profile, your app uses that URL to show the image. R2 serves the file quickly from a server near whoever's looking at it.
Why R2 Over Other Options?#
There are a bunch of file storage options out there. Here's how R2 stacks up.
| Feature | Amazon S3 | Cloudflare R2 | Supabase Storage |
|---|---|---|---|
| Price | Higher | Very low | Free tier |
| Speed | Fast | Very fast | Fast |
| Egress fees | Yes | No | Yes, past a free quota |
| Setup | Complex | Simple | Easiest |
When to Use Each:#
- R2. Best for most apps, especially ones with lots of downloads
- S3. If you're already living in the Amazon ecosystem
- Supabase Storage. If you're using Supabase for your database anyway
This lesson ends with a short activity.
