Keeping files in object storage

A bucket keeps whole files by key, copied across zones and private until you say otherwise. See how a browser can upload straight into it without holding a single key, and how old files sink to cheaper tiers.

Level: BasicWatch: 13 steps · ~1 minuteSend requests yourselfRecall: 3 questions · 8 cardsCompare 4 places for uploadscurl · TypeScript

What you'll take away

  • Explain why a bucket has keys, not folders, and why renaming one means copying
  • Sign a short-lived presigned URL so the browser uploads straight to the bucket
  • Pick hot, cool or archive, and know an archived file needs a restore first
  • Know why files belong in a private bucket, not a server's disk or the database

The 1-minute version

Tap a point and the picture below plays that step.

4Compare them all
A bucket is a list of keys, not foldersS3 API · MinIO
browser · no keys
your app · holds the keys
bucket photos · private
3 zones · 3 copies a file
day 0 · 09:00 (model)
List 2026/11/ → …
Step 1 / 13 · step by step
3files
3/3zone
3 · 0 · 0hot · cool · archive
–link
–last answer

The picture: you stand on the plaza with the browser, which holds no keys; your app's building holds them. The bucket is the yard behind one door, and its three warehouses are zones, each with a crate per file on its roof: blue is the hot tier, indigo cool, grey archive, teal a restored copy, and a white outline marks the keys a listing returns. The gold ticket by the browser is a presigned link, its bar the minutes left. Red is a refusal. The days and minutes are the model's.

Step 4 · Every option at once, on one clock

Compare them all: Object storage

One app four ways: users upload 100 photos of 4 MB, a second server is added, the first server's disk dies, then people view every photo. See how much passes through your servers in each, and how many photos are gone.

second 0.0
The server's diskfs.writeFile('uploads/…')through servers 0 MB · not found 0 · lost 0

Use it when A one-machine project to try things; files you could make again

Skip it when As soon as there are two servers a file is only on the one that took it, and a dead disk takes every file with it

A model: no thumbnails, CDN or disk backups. The MB are photo bytes passing through your app servers, in and out. Press any tile to see it large above, with when it fits.

The tiers

TierOn S3To keepTo read
HotStandardDearestAt once, cheap
CoolStandard-IACheaper, 30-day minimumAt once, paid per GB
ArchiveGlacier Flexible RetrievalMuch cheaperRestore first: minutes to hours

Keys, not folders

There is no directory to create or rename. A "folder" in the console is a shared prefix, and renaming one means copying every object under it to a new key. Pick key names you won't need to change, like uploads/<user id>/<random id>.jpg.

Who reads what

Keep buckets private. Your app holds the keys and hands out presigned URLs: one method, one key, a few minutes. Public files go out through a CDN that is allowed to read the bucket. The database keeps only the key and the details, never the bytes.

In real code

s3.sh
#!/bin/sh
# S3's API against MinIO in Docker (an S3-compatible server on your machine; no cloud account): a bucket, keys that
# only look like folders, a listing by prefix, then a presigned upload and download, and a link that expires.
# image: minio/minio:latest
set -eu
name="${MINDLOOP_NAME:-mindloop}-s3"
export S3_KEY=mindloop S3_SECRET=mindloop-secret
docker run -d --rm --pull=never --name "$name" -p 127.0.0.1::9000 \
  -e MINIO_ROOT_USER="$S3_KEY" -e MINIO_ROOT_PASSWORD="$S3_SECRET" minio/minio:latest server /data >/dev/null
trap 'docker stop "$name" >/dev/null 2>&1' EXIT
s3="http://$(docker port "$name" 9000 | head -n 1)"
until curl -sf "$s3/minio/health/ready"; do sleep 0.3; done
# requests signed with your keys (curl signs them with AWS Signature Version 4)
aws() { curl -sf --aws-sigv4 "aws:amz:us-east-1:s3" --user "$S3_KEY:$S3_SECRET" "$@"; }
aws -X PUT "$s3/photos"                                                   # a bucket
printf 'meow' | aws -X PUT --data-binary @- "$s3/photos/2026/11/cat.txt"  # the key is the whole path
printf 'woof' | aws -X PUT --data-binary @- "$s3/photos/2026/12/dog.txt"
keys=$(aws "$s3/photos?list-type=2&prefix=2026/11/" | tr '<' '\n' | sed -n 's/^Key>//p')
# a presigned URL: your server signs it, the browser uses it with no keys at all
sign() { node --experimental-strip-types --no-warnings presign.ts "$@"; }
put=$(sign PUT "$s3/photos/uploads/avatar.txt" 300)
up=$(printf 'hi' | curl -s -o /dev/null -w '%{http_code}' -X PUT --data-binary @- "$put")
get=$(sign GET "$s3/photos/uploads/avatar.txt" 2)
body=$(curl -s "$get")
anon=$(curl -s -o /dev/null -w '%{http_code}' "$s3/photos/uploads/avatar.txt")   # no signature: private
sleep 3
late=$(curl -s -o /dev/null -w '%{http_code}' "$get")                            # past its 2 seconds
[ "$keys" = "2026/11/cat.txt" ] && [ "$up" = 200 ] && [ "$body" = hi ] && [ "$anon" = 403 ] && [ "$late" = 403 ] ||
  { echo "unexpected: keys=$keys up=$up body=$body anon=$anon late=$late"; exit 1; }
echo "prefix 2026/11/ lists $keys · presigned PUT $up · presigned GET \"$body\" · the same object without a signature $anon · the GET link after 3 s $late (expired)"
Run: sh s3.sh (needs Docker and the minio/minio image: the S3 API on your machine, no cloud account)It printed: prefix 2026/11/ lists 2026/11/cat.txt · presigned PUT 200 · presigned GET "hi" · the same object without a signature 403 · the GET link after 3 s 403 (expired)

The S3 API, really run against MinIO in Docker (an S3-compatible server on your machine): curl signs requests with your keys to make a bucket, PUT two files and list one prefix; then a presigned PUT and GET with no keys at all, the same file asked for unsigned (403), and the GET link after it ran out (403). Below is what it printed.

Common questions

How is object storage different from a file system?

It keeps whole files by key in one flat list: no real folders, / is just a character. You can't change part of a file, only PUT the whole thing again. You reach it over an HTTP API, it grows almost without limit, and there are no disks to look after.

Can I rename a folder in a bucket?

There's no folder to rename, only a prefix many keys share. Renaming means copying every object under it to a new key and deleting the old ones, so pick keys you won't need to change, like uploads/<user id>/<random id>.jpg.

Read: keys, not folders

How can users upload big files without going through my server?

Have the app sign a short-lived presigned PUT URL for that one key, and let the browser upload straight to the bucket. The secret key stays on your server and the file never eats your app's bandwidth or memory. For very big files, use a multipart upload in pieces.

What if someone shares a presigned link?

Anyone holding it can use it until it expires: the signature covers a key, a method and a time, not a person. After that the bucket answers 403 by itself, with nothing to revoke. So keep links as short-lived as the job allows.

Why should a bucket be private?

Public buckets are behind a lot of data-leak stories. Keep them closed (Block Public Access, on S3) and an unsigned request gets 403. Whoever needs to read goes through a presigned URL, or a CDN that is the only thing allowed to read the bucket.

Read: who reads what

Why does a GET fail once a file has moved to archive?

Archive tiers like S3 Glacier Flexible Retrieval are cheap because you can't read them at once: a GET gets 403 InvalidObjectState. Ask for a restore, wait minutes to hours, and you get a temporary copy for the days you asked. Files people open often don't belong there.

Why not keep uploads on the server's own disk?

Then only that machine has them: add a second server behind the load balancer and it can't see them, and when that disk dies the files go with it. Object storage keeps copies in several zones, and any server can read them.

Why not keep user photos as BLOBs in the database?

The database swells fast, backups and restores slow down, every replica copies every byte, and every read and write runs through the app. Keep the file in object storage and only its key and details in the database.

Next lesson

CachingLevel: Basic

Files are now kept safely and cheaply; next, keep hot answers close and fast in a cache, and know when its copy goes stale.