Reputation: 94
I need to upload files directly to S3 via presigned URLs generated by backend REST API using multipart upload. I need to limit size of the uploaded files, but without creating policies to limit it on whole bucket. Is there some way to limit uploaded files via presigned URL?
I thought about limiting it via Content-Length header, but I am not sure if it's good approach.
Upvotes: 2
Views: 1212
Reputation: 835
A multipart/form-data request may contain multiple parts (files) separated by a boundary. When uploading multiple files in a single request, the content-length
header value will include the whole request data for all of the files and all of the boundaries.
If users are only uploading only one file per presigned URL then using the Content-Length header could work. But if you're allowing multiple files to be uploaded in a presigned URL HTTP request, then you need to calculate the size of each of the files in the message body
and compare the size of each file with the file-size limitation.
If possible, it is best to do this calculation with javascript before the HTTP request is ever sent to S3 or to a backend.
Upvotes: 1