Skip to content

Object storage and file upload

Introduction

Store images, videos, and documents as objects in dedicated storage, read and written by URL, so large files need not pass through the app server.

Why use it

  • Stateless application servers: keeping files off local disk lets you add or remove machines freely.
  • Cheap, near-unlimited capacity, and high durability, usually with built-in replicas.
  • Pair with a CDN to deliver images and video to users worldwide.
  • Does not consume the application’s bandwidth and memory.

How to do it

  • Concepts: a bucket is the top-level container, an object is the file, and a key is the path-like name.
  • S3 compatibility: the interface defined by Amazon S3 has become the de facto standard. MinIO, Alibaba Cloud OSS, Tencent Cloud COS, Cloudflare R2, and most others support it, so switching vendors costs less.
  • Presigned URLs (recommended upload path):
    1. The client tells the backend “I want to upload a.jpg”.
    2. After checking permissions, the backend returns a time-limited upload URL.
    3. The client PUTs the file straight to object storage; traffic never hits the backend.
    4. After upload, the client notifies the backend, which stores the file key in the database.

Component comparison

Alibaba Cloud OSS

Cloud-managedPay-as-you-goOpsLow

Alibaba Cloud's object storage, dedicated to storing files such as images, videos and documents, each with its own URL.

Best forProjects with users in China and services deployed on Alibaba Cloud.

Avoid whenUsers are mainly overseas, or the project does not use the Alibaba Cloud ecosystem.

Pros

Access speed and stability inside China are both fairly good

Capacity grows with what you use, so you do not estimate a ceiling first

It can be paired with Alibaba Cloud CDN to speed up access

Cons

Storage, traffic, and requests are billed as separate items, and volume gets expensive

A wrong permission or hotlink setting can leak the files

The data is tied to Alibaba Cloud, and moving it out needs an extra transfer

Official docs ↗

Tencent Cloud COS

Cloud-managedPay-as-you-goOpsLow

Tencent Cloud's object storage, similar in function to Alibaba Cloud OSS, with convenient integration with the WeChat and mini-program ecosystem.

Best forMini-programs and projects deployed on Tencent Cloud.

Avoid whenThe project does not use Tencent Cloud.

Pros

Good access in China, with convenient integration with other Tencent Cloud services

More integration documentation for mini-program and WeChat-related projects

Capacity grows elastically with usage

Cons

Also billed for storage, traffic and requests, so costs grow quickly with heavy traffic

Permission configuration is complex, and misconfiguration can leak files

Tied to Tencent Cloud, and migration costs extra

Official docs ↗

AWS S3

Cloud-managedPay-as-you-goOpsLow

Amazon's object storage, also the industry "standard": many other storage products imitate its interface.

Best forProjects facing overseas users or already using AWS.

Avoid whenUsers are mainly in China and you do not use AWS.

Pros

It is stable and mature, with the most complete features and public material

SDKs and tools are well supported in each language

The spread of regions and the ecosystem fit overseas users better

Cons

Speed and compliance inside China are weaker than with a domestic cloud vendor

Storage, requests, and traffic are billed separately, which is hard to estimate

IAM and bucket policies are complex, so permissions are easy to get wrong

Official docs ↗

MinIO (self-hosted S3-compatible)

Self-hosted open sourceOpen sourceOpsMedium

A self-deployed object storage service with an S3-compatible interface, usable on your own servers or in your own data center.

Best forInternal-network deployments, requirements on data location, or simulating S3 in dev and test environments.

Avoid whenNobody is responsible for ops and you cannot accept the risk of losing files.

Pros

S3-compatible interface, so switching code to cloud storage later takes little change

Data stays in your hands, suited to internal networks or high-compliance scenarios

No traffic-based bills

Cons

Disk failures, backups and scaling are all your responsibility

Servers and bandwidth still cost money, and high availability requires multi-node deployment

You must configure HTTPS, permissions and monitoring yourself

Official docs ↗

Local disk

Built into the frameworkOpsLow

Store files directly in a folder on the server, the simplest approach.

Best forPersonal sites, small single-machine projects, few files.

Avoid whenYou need multi-server deployment or containerized stateless deployment, or the files are important and numerous.

Pros

Zero configuration: no account to apply for and no extra service to start

The files are on this machine, so development and debugging are the most direct

There is no separate storage bill, so a small project costs nothing extra

Cons

Files are not shared across machines, and an upload exists on only one of them

Changing machines, or a dead disk, means you have to back up yourself

Image traffic uses this machine's bandwidth, and there is no CDN

Checklist

  • Buckets are private; generate presigned URLs on demand or serve via a controlled CDN
  • Upload size and file type are limited; scan for malware when needed
  • Keys are random; the database stores only the key and metadata
  • Versioning or cross-region backup is enabled
  • Lifecycle rules clean up temporary files automatically
  • Access credentials follow least privilege and are not committed to the repo — see Secrets management