Skip to content

Join the Seedly owners community →

File Storage

Cloudflare R2 Basics

Why files need object storage and how Cloudflare R2 works

Written by 5 min read1 activity
Buzz, your presenter

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!

Buzz drops a photo, a document and a film reel into wooden buckets, each with a brass tag
Object storage keeps each file as an object in a bucket

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#

Buzz waves files through an open wooden toll gate with an empty coin tray
R2 charges no egress fees when files are downloaded

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.

FeatureAmazon S3Cloudflare R2Supabase Storage
PriceHigherVery lowFree tier
SpeedFastVery fastFast
Egress feesYesNoYes, past a free quota
SetupComplexSimpleEasiest

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.