s3 直接上传限制文件大小和类型 [英] s3 direct upload restricting file size and type

查看:114
本文介绍了s3 直接上传限制文件大小和类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

一个新手问题,但我用谷歌搜索了一下,似乎找不到任何解决方案.

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

我想让用户直接上传文件到 S3,而不是先通过我的服务器.通过这样做,在实际上传到 S3 之前,有什么方法可以检查文件的大小限制和允许的类型吗?最好不要使用 flash,而是使用 javascript.

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.

推荐答案

如果您在谈论安全问题(人们将大文件上传到您的存储桶),是的,您可以通过基于浏览器的上传到 S3 来限制文件大小.

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.

这是policy"变量的示例,其中content-length-range"是关键点.

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

"expiration": "'.date('Y-m-dTG:i:s', 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]
]

在这种情况下,如果上传文件大小> 10mb,上传请求将被亚马逊拒绝.

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

当然,在开始上传过程之前,您应该使用 javascript 检查文件大小,如果有就发出一些警报.

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

在 javascript 中获取文件大小

这篇关于s3 直接上传限制文件大小和类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆