2012-11-03 84 views
0

我試圖通過HTML上傳文件上傳到S3,我試圖按照本教程:亞馬遜S3 CORS POST失敗,jQuery的文件上傳

http://pjambet.github.com/blog/direct-upload-to-s3/

我能張貼文件通過常規的HTML形式。但是,如果我發佈與JQuery-file-upload插件相同的表單,我會從亞馬遜獲得403。

這裏是我的形式:

<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"> 

這裏是我的jQuery的上傳:

$('.direct-upload').fileupload({ 
     url: $(this).attr('action'), 
     type: 'POST', 
     autoUpload: true, 
     dataType: 'xml', 
     add: function (event, data) { 
     jqXHR = data.submit(); 
     } 

我從亞馬遜這樣的回答:

OPTIONS https://youboox_dev.s3.amazonaws.com/ 200(OK)
POST https://youboox_dev.s3.amazonaws.com/ 403(禁止)

============================================= ===========

我很確定我的政策和簽名是正確的,因爲當我通過提交按鈕提交這個表單時,我得到了一個來自亞馬遜的好迴應,'不能下載我剛剛上傳的文件:

<PostResponse> 
    <Location>https://youboox_dev.s3.amazonaws.com/tottotoCVBNBV</Location> 
    <Bucket>youboox_dev</Bucket> 
    <Key>test-file-name</Key> 
    <ETag>"d41d8cd98f00b204e9800998ecf8427e"</ETag> 
</PostResponse> 

回答

0

我有類似的選項(我從來沒有測試過直接表單POST)。什麼固定對我來說是增加了水桶政策:(我承認,只是從另一個桶別人複製這個盲目地建立了,所以我不知道這是actaully需要的這個部分)

{ 
"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/*" 
    } 
] 
}