LeonAdvice
LeonAdvice

Reputation: 123

How to limit file size of AWS S3 pre-signed PUT upload?

Hello I'm working on an app where user can upload their own video (yes like Tiktok). I going with the direct upload with pre-signed using PUT route for maximizing upload speed.

My question is how do I really limit the file size that my user can upload for a video?

A solution I came up with is to use lambda to check for content-length of the object that got upload. But as far as I know that content-length properties was being set in the header of the client. What if the content-length in the header and the actual file size was upload to s3 did not match up? Is it even possible that someone can do that with PUT upload?

Upvotes: 6

Views: 4298

Answers (1)

lennon310
lennon310

Reputation: 12689

A solution I came up with is to use lambda to check for content-length of the object that got upload.

An alternative is to set content-length-range matching POST policy.

What if the content-length in the header and the actual file size was upload to s3 did not match up

Not sure why this could happen, but other than using content-length property, multipart upload is worth considering too. It is just a series of regular requests. You initiate a multipart upload, send one or more requests to upload parts, and then complete the multipart upload process. You sign each request individually.

A Node.js plugin that supports S3-streaming-upload.

Upvotes: 2

Related Questions