[英]Amazon S3 CORS POST fails with JQuery-file-upload
I'm trying to upload files to S3 through an HTML uploader, I tried to follow this tutorial : 我正在尝试通过HTML上传器将文件上传到S3,我尝试遵循此教程:
http://pjambet.github.com/blog/direct-upload-to-s3/ http://pjambet.github.com/blog/direct-upload-to-s3/
I'm able to post files through regular html form. 我可以通过常规的html表单发布文件。 But if i post the same form with JQuery-file-upload plugin i get a 403 from Amazon. 但是,如果我使用JQuery-file-upload插件发布相同的表单,则会从Amazon获得403。
Here is my form : 这是我的表格:
<form accept-charset="UTF-8" action="https://youboox_dev.s3.amazonaws.com" enctype="multipart/form-data" class='direct-upload' method="POST">
<input type="hidden" name="key" value="test-file-name">
<input type="hidden" name="AWSAccessKeyId" value="AKIZ[...]YSCA">
<input type="hidden" name="acl" value="private">
<input type="hidden" name="success_action_status" value="201">
<input type="hidden" name="policy" value="<%= Facades::AmazonFacade.policy %>">
<input type="hidden" name="signature" value="<%= Facades::AmazonFacade.signature %>">
<input type="file" name="file">
<input type="submit" value="Load this file">
And here is my jquery-uploader : 这是我的jquery-uploader:
$('.direct-upload').fileupload({
url: $(this).attr('action'),
type: 'POST',
autoUpload: true,
dataType: 'xml',
add: function (event, data) {
jqXHR = data.submit();
}
I get this answer from amazon : 我从亚马逊得到这个答案:
OPTIONS https://youboox_dev.s3.amazonaws.com/ 200 (OK) 选项https://youboox_dev.s3.amazonaws.com/ 200(确定)
POST https://youboox_dev.s3.amazonaws.com/ 403 (Forbidden) POST https://youboox_dev.s3.amazonaws.com/ 403(禁止)
======================================================== ================================================== ======
I'm pretty sure my policy and signature are correct since when i just submit this form through the submit button, i get a ok response from amazon and 'im able to download the file i just uploaded : 我非常确定我的政策和签名正确无误,因为当我仅通过“提交”按钮提交此表单时,我得到了来自亚马逊的好的答复,并且“我能够下载我刚刚上传的文件:
<PostResponse>
<Location>https://youboox_dev.s3.amazonaws.com/tottotoCVBNBV</Location>
<Bucket>youboox_dev</Bucket>
<Key>test-file-name</Key>
<ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag>
</PostResponse>
I was having similar option (I never tested a direct form POST). 我也有类似的选择(我从未测试过直接表单POST)。 What fixed it for me was adding a bucket policy: 对我来说解决的是添加了存储桶策略:
{
"Version": "2008-10-17",
"Id": "Policy1347277692345",
"Statement": [
{
"Sid": "my-user",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::123456789:user/my-user"
},
"Action": [
"s3:AbortMultipartUpload",
"s3:GetObjectAcl",
"s3:GetObjectVersion",
"s3:DeleteObject",
"s3:DeleteObjectVersion",
"s3:GetObject",
"s3:PutObjectAcl",
"s3:PutObjectVersionAcl",
"s3:ListMultipartUploadParts",
"s3:PutObject",
"s3:GetObjectVersionAcl"
],
"Resource": "arn:aws:s3:::my-bucket/*"
},
{
"Sid": "world-readable",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::my-bucket/*"
}
]
}
(I admit to just copying this blindly from another bucket someone else had set up so I don't know which parts of this are actaully needed.) (我承认只是从别人设置的另一个存储桶中盲目复制它,所以我不知道实际上需要哪个部分。)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.