What Is File Storage?
Why uploads and images don't belong in your database or on your server, and how object storage works

Pixl presents
Saving uploads to your server's disk works great until the next deploy deletes them all. Let's put files somewhere sane.Saving uploads to your server's disk works great until the next deploy deletes them all. Let's put files somewhere sane.

Profile pictures, PDFs, videos, product photos. Sooner or later your app has to hang on to files that people upload, and they have to live SOMEWHERE. I built a lil Bulk Image Processor that chews through 100 images in about 5 minutes... and every one of those images needs a home when it's done. This lesson covers where files should live, why, and what to look for in a file storage service.
Files Are Different From Data#
A database is great at small, tidy pieces of information. A name, an email address, an order total. It was never built to hold a 20 MB video.
So you might think, fine, I'll just save uploads to my server's disk. That falls apart fast too.
- Many hosts wipe the disk when your app restarts or redeploys, so uploads vanish.
- Apps often run on more than one server, and a file saved on one isn't on the others.
- Serving big files is slow and it eats your server's bandwidth.
So apps split the job. Files go to a storage service, and the database keeps a small record that points to each file.
What Is Object Storage?#
Most file storage services use a model called object storage. Three words and you've got it.
- Bucket. A container for your files, kinda like a top-level folder. You might have one for user avatars and another for documents.
- Object. A single file, plus a lil info about it, such as its type.
- Key. The object's name inside the bucket, like
avatars/user-123.png. It looks like a folder path, but it's honestly just a name.
You put objects in with an API call and get them back by key, or through a URL.
Where File Storage Sits in Your App#
Step 1. The User Picks a File#
They choose a photo on your upload page.
Step 2. Your App Sends It to Storage#
Either your server uploads it, or your server hands the browser a short-lived link so it can upload straight to storage.
Step 3. Storage Saves It#
The file lands in your bucket under a key.
Step 4. Your Database Remembers Where It Is#
You save the key or URL right next to the user's record.
Step 5. Your Pages Show It#
When the page loads, it uses that URL to display the image.
Browser --- upload ---> File storage (bucket)
| |
v v
Your app --- saves key ---> Database
|
Page shows the image using the stored URLPublic and Private Files#
Not every file should be visible to the whole world. A product photo can be public. An invoice or somebody's ID document absolutely can't.
Storage services let you keep a bucket private and hand out temporary links when someone's allowed to see a file. You'll set that up in the R2 chapter.
What to Look For#

When you're comparing file storage services, ask yourself these questions.
- Is it S3 compatible? Amazon S3 set the standard. Lots of services speak the same API, so the same code and tools work with them.
- What does storage cost? It's usually priced per GB stored per month.
- What does downloading cost? Some services charge every time a file gets served, which is called egress. For busy apps that can be the BIGGEST part of the bill.
- How do public and private files work? Look for easy temporary links.
- Is it fast for your users? A service with a global network serves files from somewhere nearby.
The Service in This Module#
This module covers Cloudflare R2, an object storage service that works with the S3 API. Its chapter walks through how R2 works, how to set up and lock down a bucket, and then how to upload files from code.
TL;DR#
- Files don't belong in your database or on your server's disk
- Object storage keeps files as objects, inside buckets, named by keys
- Put the file in storage and its key or URL in your database
- Keep files private by default and use temporary links when you need them
- Compare services on S3 compatibility, storage cost, download cost and speed
- This module covers Cloudflare R2
What's Next?#
Next up is the Cloudflare R2 chapter, where you'll see object storage doing its thing for real...
This lesson ends with 2 short activities.
