Book a 30-min callBook a call

System design: file uploads with presigned URLs, multipart uploads and processing

How to design file uploads: presigned URLs straight to object storage, multipart and resumable uploads, magic-number checks, malware scans and a CDN.

A browser window sending an upload straight to a bucket after an API box hands it a key, the bucket feeding a scanner circle and a queue of blocks, and a CDN circle serving users.
Written by
BYD Tech
Published
Topic
Deep dives
Reading time
15 min read

Questions people ask

Should files be uploaded through my server or directly to S3?

Directly, in almost every case. Your API authorizes the upload and returns a short-lived presigned URL, and the browser sends the bytes to storage. Proxy only small files that must be transformed or encrypted before they are stored.

How long should a presigned upload URL stay valid?

Minutes. AWS describes presigned URLs as bearer tokens: anyone holding one can use it, more than once, until it expires. The SDKs allow up to 7 days, but an upload starts right after the URL is issued, so a short expiry costs nothing.

Is checking the file extension and MIME type enough?

No. Both come from the client and can be faked. Check the stored bytes against an allowlist of magic numbers, check the real size, scan the file and re-encode images. OWASP recommends layering these, because each one alone can be bypassed.

When should I use multipart upload?

AWS recommends it for objects of 100 MB or more, and it helps on unreliable connections at smaller sizes too, because only failed parts are re-sent. Add a lifecycle rule that aborts incomplete multipart uploads, or abandoned parts stay stored.

What is the tus protocol?

An open HTTP protocol for resumable uploads. The client creates an upload, sends bytes with PATCH requests carrying an offset, and after an interruption asks the server for the current offset with HEAD and continues from there. It works in front of any storage backend.

Building something like this?