Where your web app should keep uploaded files
Short answer: Keep user uploads out of your app server's own disk and put them in object storage, such as Amazon S3, Cloudflare R2 or a comparable service. Let the browser upload straight to storage using short-lived presigned URLs, keep the bucket private by default, store only the file's key and metadata in your database, and set lifecycle rules so abandoned files don't pile up. This keeps the app easier to scale, back up and move.
Founders building a first web app, a client portal, a job-tracking tool or a marketplace, often start by saving uploaded files into a folder on the server. It works for the demo. It becomes a problem when you add a second server, redeploy, migrate hosts or need a backup you can trust. Here's what object storage is, how uploads work with it, when it matters and how to set it up sensibly.
What object storage is
Object storage holds files ("objects") in containers usually called buckets, each identified by a key, which is essentially its path and name. You don't mount it like a disk; your app reads and writes through an API. Amazon S3 is the best-known example, and several providers, Cloudflare R2 among them, offer S3-compatible APIs, so the same libraries and patterns tend to work across them.
What it gives a small app, compared with the server's disk:
- Separation: your servers can be replaced or multiplied without copying files around.
- Durability and scale managed by the provider rather than by you.
- Fine-grained access: private by default, with temporary access granted per file.
- Lifecycle tools to move or delete files automatically.
How uploads work: presigned URLs
The common pattern is to let the browser upload directly to storage instead of streaming every file through your app server.
AWS's S3 documentation describes presigned URLs as a way to let someone upload an object to your bucket without that person needing AWS credentials or permissions of their own. A presigned URL is limited by the permissions of whoever created it, and you set an expiry date and time when generating it. The AWS guide also notes the file uploaded must match the object key in the URL, and warns about uploading to a key that already exists, so generate a unique key per upload.
Cloudflare's R2 documentation describes the same concept: the signature sits in the URL itself and authorises anyone with it to perform one specific operation on one specific object until it expires. R2's expiry can be set anywhere from 1 second to 7 days. Cloudflare's security advice is to treat presigned URLs as bearer tokens, share them only with intended recipients and use short expiry times for sensitive operations. It also notes that if browsers will use the URLs, you need CORS rules on the bucket, and that R2's presigned URLs work on its S3 API domain rather than on custom domains.
In practice the flow looks like this:
- The user picks a file in your app.
- Your app's backend checks they're allowed to upload, decides the object key (for example
projects/1234/uploads/9f8e.pdf) and generates a presigned upload URL with a short expiry. - The browser uploads the file directly to storage using that URL.
- The browser tells your backend the upload finished; the backend records the key, file name, size, type and owner in the database.
- When someone needs to view the file, the backend checks permission and issues a short-lived presigned download URL.
When it matters (and when it doesn't)
It matters when:
- Users upload documents, photos or videos that must survive redeploys and server changes.
- You run, or might run, more than one app server.
- Files are private: contracts, invoices, ID documents, client deliverables.
- Storage will grow steadily and you want predictable housekeeping.
It matters less when:
- The only files are a handful of images you upload yourself through a CMS that already handles storage.
- The app is a short-lived prototype. Even then, starting with object storage is rarely more work than doing it later.
Setting it up sensibly
Keep buckets private by default
Make public access the exception. Public buckets (or public folders within them) suit assets meant for anyone, such as product images. Private user uploads should only be reached through permission checks and short-lived URLs.
Store keys, not URLs, in your database
Signed URLs expire. Save the object key and generate URLs when needed. This also makes it easier to switch providers or add a CDN later.
Validate on both sides
Check file type and size in the browser for a good experience, and enforce limits on the backend when issuing upload URLs. Signing the content type, as Cloudflare's docs describe for some libraries, helps stop a different kind of file being uploaded than the one you approved.
Name keys predictably
A structure like tenant/record/uuid.ext makes access rules, clean-up and exports straightforward. Keep the user's original file name in the database for display.
Use lifecycle rules
AWS describes S3 Lifecycle as a way to move objects to lower-cost storage classes or delete expired objects automatically, configured per bucket. Typical uses: delete files from abandoned uploads after a few days, move old archives to cheaper storage. AWS notes there are costs for transition requests; check each provider's pricing page before setting rules.
Plan backups and deletion
Decide what happens when a user deletes a record or closes an account: are files removed immediately, after a grace period, or retained? Also decide how you'd recover from an accidental deletion, for example with versioning or a separate backup copy.
FAQ
Is object storage expensive for a small app?
Costs depend on volume stored, requests and data transfer, and vary by provider. Check current pricing pages; for most small apps, storage is a modest line compared with hosting, but egress-heavy apps should compare carefully.
Can I serve images from object storage on my website?
Yes, usually through a public bucket or a CDN in front of it. For user-specific private files, use short-lived signed URLs instead.
How long should a presigned URL last?
As short as practical for the task: minutes for an upload or a download link opened right away. Cloudflare's docs recommend short expiry times for sensitive operations.
What happens to files if I change hosting provider?
If files live in object storage and your database stores keys, you can move the app without moving files. Switching storage provider is a separate, manageable migration.
Building an app where customers upload documents or photos and unsure how to structure storage and access? Walk us through your upload flow and we'll sketch a setup that scales. Our page on custom web apps for small businesses explains how we plan apps like this from the start.