Presigned URLs, multipart and direct uploads
Let browsers upload to and download from private buckets: presigned URLs and POSTs, multipart uploads, CORS, limits and cleanup.
S3 buckets, objects and consistencyS3 access control and Block Public Access
Presigned URLs, multipart and direct uploads
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- A presigned URL is a request your server signs in advance. Whoever holds it can make that one request, with the signer's permissions, until it expires.
- It can't outlive the credentials that signed it. A URL signed with role credentials dies with the session, whatever expiry you asked for.
- A presigned PUT can't express a size range. A presigned POST can, along with conditions on the key prefix and content type.
- Multipart upload splits an object into up to 10,000 parts of 5 MiB to 5 GiB, sent in parallel and retried one at a time.
- Browsers need a CORS rule on the bucket, and must be able to read the ETag header to complete a multipart upload.
- Treat every upload as untrusted: server-chosen keys, size limits, a quarantine prefix and checks before anyone else can download it.
The relay problem
A user wants to upload a 2 GB video. The obvious design sends it to your server, which forwards it to S3. Now your server holds connections open for minutes, buffers bytes it doesn’t care about and needs to scale with upload traffic. On Lambda or API Gateway, payload limits stop you outright.
The bytes should go straight to S3. But the bucket is private and the browser has no AWS credentials. You want to hand it a permission slip: this one object, this one action, for a few minutes.
Presigned URLs
A presigned URL is an ordinary S3 request that your backend signs ahead of time, with the signature in the query string. Signing is local arithmetic. No call goes to AWS.
url = s3.generate_presigned_url(
"put_object",
Params={"Bucket": B, "Key": "uploads/u42/photo.jpg",
"ContentType": "image/jpeg"},
ExpiresIn=300)
Taking the generated URL apart shows what’s inside:
path: /shop-assets-demo/uploads/u42/photo.jpg
X-Amz-Algorithm AWS4-HMAC-SHA256
X-Amz-Credential testing/20261129/eu-west-1/s3/aws4_request
X-Amz-Date 20261129T041152Z
X-Amz-Expires 300
X-Amz-SignedHeaders content-type;host
X-Amz-Signature af85a6...
The method, bucket, key, expiry and signed headers are all covered by the signature. Change any of them and S3 refuses. Here the client must send Content-Type: image/jpeg.
Three rules matter. The URL carries the signer’s permissions, so the role that signs should only be able to write where uploads belong. It’s a bearer token: anyone who has the string can use it, as often as they like until it expires, so don’t log it. And it can’t outlive its credentials. Signed with an IAM user’s keys it can last up to seven days. Signed with temporary credentials, it ends when they do.
Presigned POST for browser forms
A presigned PUT can’t say “no bigger than 5 MB”. A presigned POST signs a policy document with conditions instead:
post = s3.generate_presigned_post(
B, "uploads/u42/${filename}",
Conditions=[
["content-length-range", 1, 5 * 1024 * 1024],
["starts-with", "$Content-Type", "image/"]],
ExpiresIn=300)
The browser submits a multipart form with the returned fields, and S3 checks the conditions.
Multipart uploads
One PUT tops out at 5 GB, and a dropped connection at 95% means starting again. A multipart upload has three steps:
CreateMultipartUploadreturns an upload ID.UploadPartsends numbered parts, in any order and in parallel. Each returns anETag.CompleteMultipartUploadlists part numbers and ETags, and S3 assembles the object.
Parts are 5 MiB to 5 GiB, except the last which can be smaller, with at most 10,000 of them and an object of about 50 TB. AWS suggests multipart from around 100 MB. The CLI’s aws s3 cp and the SDK transfer helpers do this for you.
On a local emulator, two 1 MiB parts uploaded fine but completion failed with EntityTooSmall. Parts of 5 MiB, 5 MiB and 1 MiB completed, with an ETag ending -3. That suffix is the part count, and it’s why a multipart ETag isn’t the file’s MD5. Use S3’s checksum features to verify integrity.
For a browser, your backend creates the upload, presigns a URL per part, and completes it at the end. To resume, call ListParts and send only what’s missing.
The browser details
The bucket needs a CORS configuration allowing your origin and the PUT method, and it must list ETag in exposed headers or your script can’t read it. CORS explains why. CORS only tells browsers what scripts may do. It grants no S3 permission.
Don’t trust what arrives
Choose the key on the server so a user can’t overwrite someone else’s file. Upload into a quarantine prefix, trigger checks from an S3 event, verify type and size from the bytes rather than the filename, and only then move the object where others can read it. Record ownership in your database. Add a lifecycle rule that aborts incomplete uploads after a few days, since orphaned parts are billed.
For downloads, sign short-lived GET URLs after your own authorization check, or use CloudFront signed URLs when you want edge caching.
About the video
The embed is Rahul Saxena’s 13-minute “S3 Multipart Upload & Presigned URLs Explained” from October 2026, a diagram-led design walkthrough with simplified JavaScript. Its description promises the direct-upload flow, upload IDs and part numbers, ETags, completion, resuming with ListParts and the risk of malicious files. It comes from a small channel, has no chapters and no audio-language flag; I judged it from the description only, since transcripts couldn’t be fetched.
What was run: the presigned URL, a real PUT to it, the POST field generation and both multipart attempts ran with boto3 against moto 5.1.22. moto doesn’t prove that S3 would enforce signatures, expiry or POST conditions. Those come from the S3 user guide, checked in November 2026.
Check yourself
Your Lambda signs a download URL with a one week expiry. Users report it stops working after a few hours. Why?
The Lambda signs with temporary role credentials. The URL stops working when those credentials expire, regardless of the requested expiry.
A user should upload a profile picture of at most 5 MB. Why not a presigned PUT?
A presigned PUT has no way to state a maximum size. A presigned POST policy can include a content-length-range condition that S3 enforces.
A 100 GiB file is uploaded with 5 MiB parts. What goes wrong?
That needs over 20,000 parts and the limit is 10,000. Parts must be at least about 10.3 MiB, and in practice larger sizes such as 64 MiB are sensible.
An upload stops halfway and the user never returns. What is left behind?
The uploaded parts. They're billed and don't appear in an object listing until the upload is completed or aborted. A lifecycle rule should abort old uploads.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.