I'm using an AWS S3 presigned url to upload picture from a client (mobile app). I want to prevent the user to upload large files. Is there a way to limit the file size of an uploaded file?
Thanks
I'm using an AWS S3 presigned url to upload picture from a client (mobile app). I want to prevent the user to upload large files. Is there a way to limit the file size of an uploaded file?
Thanks
Check out "content-length-range" in s3 policy. http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-HTTPPOSTConstructPolicy.html
The conditions in a POST policy is an array of objects, each of which is used to validate the contents of the uploaded object. You can use these conditions to restrict what is allowed in the request. Each form field that you specify in a form (except x-amz-signature, file, policy, and field names that have an x-ignore- prefix) must appear in the list of conditions.
content-length-range
The minimum and maximum allowable size for the uploaded content. This condition supports content-length-range condition match type.
I have solved this problem perfectly! Though, the POST policy can work, but use presigned urls is more comfortable.
I use nodejs as backend. And use getSignedUrl to limit the size of upload file.
It just need modify three line of aws-sdk code. And I have tried, it can work very well.
I don't know why aws-sdk of nodejs don't support it. If there is some reason, please share to me.
first, open "node_modules/aws-sdk/lib/signers/v4.js", comment the following two line
second, open "node_modules/aws-sdk/lib/services/s3.js", comment the following one line
third, write the code to generate presigned url and upload file