Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

s3 direct upload restricting file size and type

A newbie question but I have googled abit and can't seem to find any solution.

I want to allow users to directly upload files to S3, not via my server first. By doing so, is there any way the files can be checked for size limit and permitted types before actually uploading to S3? Preferably not to use flash but javascript.

like image 484
twb Avatar asked Nov 15 '12 01:11

twb


People also ask

What type of files can be uploaded to S3 bucket?

You can upload any file type—images, backups, data, movies, etc. —into an S3 bucket. The maximum size of a file that you can upload by using the Amazon S3 console is 160 GB. To upload a file larger than 160 GB, use the AWS CLI, AWS SDK, or Amazon S3 REST API.

What is the file size limit in S3?

Individual Amazon S3 objects can range in size from a minimum of 0 bytes to a maximum of 5 TB. The largest object that can be uploaded in a single PUT is 5 GB. For objects larger than 100 MB, customers should consider using the Multipart Upload capability.


1 Answers

If you are talking about security problem (people uploading huge file to your bucket), yes, You CAN restrict file size with browser-based upload to S3.

Here is an example of the "policy" variable, where "content-length-range" is the key point.

"expiration": "'.date('Y-m-d\TG:i:s\Z', time()+10).'", "conditions": [     {"bucket": "xxx"},     {"acl": "public-read"},     ["starts-with","xxx",""],     {"success_action_redirect": "xxx"},     ["starts-with", "$Content-Type", "image/jpeg"],     ["content-length-range", 0, 10485760] ] 

In this case, if the uplaoding file size > 10mb, the upload request will be rejected by Amazon.

Of course, before starting the upload process, you should use javascript to check the file size and make some alerts if it does.

getting file size in javascript

like image 84
stonyau Avatar answered Sep 20 '22 16:09

stonyau