【问题标题】:Amazon S3 CORS POST fails with JQuery-file-uploadAmazon S3 CORS POST 因 JQuery-file-upload 失败
【发布时间】:2012-10-23 22:05:20
【问题描述】:

我正在尝试通过 HTML 上传器将文件上传到 S3,我尝试按照本教程进行操作:

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

我可以通过常规的 html 形式发布文件。但是,如果我使用 JQuery-file-upload 插件发布相同的表单,我会从 Amazon 获得 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-uploader :

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

我从亚马逊得到这个答案:

选项https://youboox_dev.s3.amazonaws.com/ 200(确定)
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>

【问题讨论】:

    标签: jquery ruby-on-rails amazon-s3 cors


    【解决方案1】:

    我有类似的选择(我从未测试过直接形式的 POST)。为我解决的问题是添加存储桶策略:

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

    (我承认只是从其他人设置的另一个存储桶中盲目复制此内容,因此我不知道实际需要其中的哪些部分。)

    【讨论】:

      猜你喜欢
      • 2014-05-28
      • 2012-09-19
      • 2019-09-04
      • 1970-01-01
      • 2015-03-09
      • 1970-01-01
      • 2013-03-06
      • 1970-01-01
      • 2013-09-25
      相关资源
      最近更新 更多