FILE STORAGE / LESSON 02
Cloudflare R2 Basics.
Why files need object storage and how Cloudflare R2 works

Loading the lesson…
Loading activities…
FILE STORAGE / LESSON 02
Why files need object storage and how Cloudflare R2 works

Loading the lesson…
Loading activities…
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.
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.
So instead we use dedicated file storage services. They're built specifically to hold files reliably and serve them fast.
File storage services use something called "object storage." Sounds fancy, but it's a pretty simple idea.
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.
Cloudflare R2 is a file storage service, and here's what it brings to the table.
Let's walk through what happens when a user uploads a profile picture.
The user clicks "upload" and picks an image from their computer.
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.
You save the file's URL to your database, tied to the user's profile.
When someone views the profile, your app uses that URL to show the image. The object lives in its bucket's storage location. If you serve public files through a custom domain with caching configured, repeat requests can come from a nearby Cloudflare edge location.
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 |