I'm trying to upload files to S3 through an HTML uploader, I tried to follow this tutorial :
http://pjambet.github.com/blog/direct-upload-to-s3/
I'm able to post files through regular html form. But if i post the same form with JQuery-file-upload plugin i get a 403 from Amazon.
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 :
$('.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)
POST https://youboox_dev.s3.amazonaws.com/ 403 (Forbidden)
========================================================
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). 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.)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.