# File Storage and Uploads with Object Storage

> Accept, store and serve user files safely using object storage like S3 instead of your server's disk. Free notes, key concepts, resources and a mini project.

Canonical: https://www.internhack.in/roadmaps/tracks/backend/file-storage-uploads
Last updated: 2026-11-28

Accept, store and serve user files safely using object storage like S3 instead of your server's disk.

Intermediate · about 5 hours · difficulty 2/5

Learn first: [Resource-Oriented REST APIs](https://www.internhack.in/roadmaps/tracks/backend/rest-api-design), [Authorization: Roles and Permissions](https://www.internhack.in/roadmaps/tracks/backend/authorization-models)

Sooner or later users upload avatars, PDFs or videos. Storing them on the app server's local disk breaks as soon as you run two instances or redeploy a container. The standard answer is **object storage**: Amazon S3 and its compatible cousins (Cloudflare R2, Google Cloud Storage, Azure Blob, self-hosted MinIO).

### The mental model

Object storage is a flat key-value store for blobs. A **bucket** holds **objects**, each addressed by a key such as `users/42/avatar.png`, with metadata like content type. There are no real folders, just key prefixes. It is cheap, durable and scales without you thinking about disks.

### Upload patterns

- **Proxy upload**: the client sends the file to your API, which streams it to storage. Simple, but your server carries all the bytes.
- **Presigned URL upload** (recommended): your API checks permissions, then returns a short-lived signed URL; the client uploads directly to the bucket. Your server only stores the key in the database.
- For large files use **multipart uploads** so a failed chunk can be retried without restarting.

### Serving files

Keep buckets private by default. Serve public assets through a CDN, and serve private files with short-lived **presigned download URLs** after an authorization check.

### Security pitfalls

- Trusting the client's filename or `Content-Type`. Generate your own keys and validate type and size on the server.
- Serving user uploads from your main domain, which can enable stored XSS. Use a separate domain or force `Content-Disposition: attachment`.
- Public buckets created "just for testing" that leak customer data.

You are ready to move on when you can implement presigned uploads with size limits, record the object key in your database and serve the file back only to its owner.

## Key concepts

- **Buckets, objects and keys**
- **Presigned upload and download URLs**
- **Multipart and resumable uploads**
- **Validating type and size**
- **Serving files through a CDN**
- **Image resizing pipelines**
- **Lifecycle rules and storage classes**
- **S3-compatible stores (R2, MinIO)**

## Mini project

Add profile pictures to an API: issue a presigned upload URL limited to 2 MB images, store the key, generate a thumbnail in a background step and serve it via a presigned download URL.

## Check yourself

Why is uploading directly from the browser to S3 with a presigned URL usually better than streaming the file through your API?

## Free resources

- [Amazon S3 User Guide](https://docs.aws.amazon.com/AmazonS3/latest/userguide/Welcome.html) (AWS)
- [Working with presigned URLs](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) (AWS)
- [OWASP File Upload Cheat Sheet](https://cheatsheetseries.owasp.org/cheatsheets/File_Upload_Cheat_Sheet.html) (OWASP)
- [Cloudflare R2 documentation](https://developers.cloudflare.com/r2/) (Cloudflare)

Previous: [HTTP Caching, CDNs and Client Caches](https://www.internhack.in/roadmaps/tracks/backend/http-caching-cdn) · Next: [Transactional Email and Notifications](https://www.internhack.in/roadmaps/tracks/backend/email-notifications)

## More in Files, Email and Payments

- [File Storage and Uploads with Object Storage](https://www.internhack.in/roadmaps/tracks/backend/file-storage-uploads)
- [Transactional Email and Notifications](https://www.internhack.in/roadmaps/tracks/backend/email-notifications)
- [Payments, Webhooks and Idempotency](https://www.internhack.in/roadmaps/tracks/backend/payments-webhooks)

## Related

- [Roadmaps](https://www.internhack.in/roadmaps)
- [Backend Developer Roadmap](https://www.internhack.in/roadmaps/tracks/backend)
