๐Ÿ“ API

S3-compatible object storage: buckets, keys, and URLs

P
Author
PyLand Team
๐Ÿ“…
Published
18.09.2026
โฑ๏ธ
Reading time
1 min
๐Ÿ‘๏ธ
Views
3
๐ŸŒฟ
Level
Medium

A regular folder works on one computer. After deployment it is unreliable: a
container can be replaced, and several application instances do not share one local
disk. Object storage solves this problem.

S3 stores files as objects inside a bucket. The application identifies one by
its key. A key may look like covers/uuid.webp, but it is not a local filesystem
path. The bucket says โ€œwhich collectionโ€; the key says โ€œwhich objectโ€.

Store these separately:

  • key โ€” the stable identifier used for reading and deletion;
  • URL โ€” an access mechanism that may be temporary;
  • metadata โ€” size, detected type, and owner.

Do not parse a key back out of a URL; domains, encoding, and signatures can change.

One file’s journey

  1. The application validates the upload.
  2. The server generates an unpredictable key.
  3. A storage adapter saves the bytes.
  4. The database stores the key and metadata, not a temporary URL signature.
  5. The app builds a URL for reading and uses the saved key for deletion.
from typing import Protocol

class Storage(Protocol):
    def save(self, key: str, data: bytes, content_type: str) -> str: ...
    def delete(self, key: str) -> None: ...

One contract supports local storage in development and tests and S3 in production.
The FastAPI route should not know boto3 details.

This lets a learning project work locally without cloud credentials. Connecting S3
later does not require rewriting the routes.

Generate unpredictable server-side keys, grant only required IAM actions, never
commit credentials, set the correct ContentType, and avoid making a whole bucket
public for one file. Use short-lived presigned URLs for private access. A presigned
URL is temporary access, not a stable database identifier or a replacement for app
authorization. The user authenticates in your application first; only then does the
server decide whether to issue a link. Expiring a presigned URL does not delete the
objectโ€”it only ends access through that signature.

Official documentation

Your reaction to the article

๐Ÿ’ฌ Comments (0)

๐Ÿ” Sign in to leave a comment
๐Ÿšช Login
๐Ÿ’ญ

No comments yet

Be the first to share your opinion about this article!

๐Ÿ”— Similar

Similar articles

Continue learning with these materials

๐Ÿ“

What Is an API and Why Does It Exist

Every time you open a weather app, pay with a card, or see recommendations on...

๐Ÿ“… 08.05.2026 ๐Ÿ‘๏ธ 433
๐Ÿ“

Secure file uploads: size, type, names, and storaโ€ฆ

Choosing a photo looks simple: the browser sends a file and the server stores it....

๐Ÿ“… 18.09.2026 ๐Ÿ‘๏ธ 3
๐Ÿ“

Cookie sessions and CSRF in server-rendered web aโ€ฆ

A cookie session connects browser requests to a user. A signed cookie prevents undetected modification,...

๐Ÿ“… 18.09.2026 ๐Ÿ‘๏ธ 4

Did you like the article?

Subscribe to our updates and be the first to receive new articles. Grow with PyLand!