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:
(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.)