1

我正在尝试使用 SWFUpload 和 AWS-SDK 对 S3 进行预签名。长话短说,它不起作用。

我因此设置了 SWFUpload(请原谅咖啡脚本):

@swfu = new SWFUpload
         flash_url: "<%= asset_path 'swfupload.swf' %>"
         file_size_limit: "1000 MB"
         file_types: "*.mp3"
         file_queue_limit:1
         debug: true
         upload_url: "http://<%= configatron.aws.cms.bucket %>.s3.amazonaws.com"
         button_placeholder_id : "SWFUploadButton"
         button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE
         button_width: '112'
         button_height: '33'
         button_text: '<button class="orange-button">Upload MP3s</button>',
         button_cursor : SWFUpload.CURSOR.HAND
         http_success : [201, 303, 200]
         file_post_name: "file"
         file_queued_handler: (data) =>
           @queued(data)

当文件排队时,运行:

$.ajax
  url: '/uploads/new'
  data: { key: file.name, bucket: '<%= configatron.aws.cms.bucket %>' }
  success: (data) =>
    @upload(data)

/uploads/new最后,使用 aws-sdk gem 指向一个返回 JSON 的控制器(我已经剪掉了一些关于实例化存储桶的部分):

  policy = bucket.presigned_post key: key, success_action_status: 201, acl: 'public-read'
  render json: policy

示例 JSON 响应如下所示:

{"AWSAccessKeyId":"MY_KEY_ID",
 "key":"blutrotermond.mp3",
 "policy":"base64-encoded-policy",
 "signature":"the-signature",
 "acl":"public-read",
 "success_action_status":"201"}

回到 javascript 领域,带着签名,我接受这个响应并将参数添加到 SWFUpload:

upload: (data) ->
  @swfu.setPostParams data
  console.log "uploading...."
  @swfu.startUpload()

然后 SWFUpload 的控制台告诉我,亚马逊对我的签名过程不满意(或者我假设,因为无论 SWFUpload 做什么神奇的事情都意味着 POST 本身不会出现在 Chrome 的检查器中,从而使我无法更直接地查看发布的内容):

SWF DEBUG: Event: fileQueued : File ID: SWFUpload_0_0
SWF DEBUG: Event: fileDialogComplete : Finished processing selected files. Files selected: 1. Files Queued: 1
SWF DEBUG: StartUpload: First file in queue
SWF DEBUG: Event: uploadStart : File ID: SWFUpload_0_0
SWF DEBUG: Global Post Item: signature=signature
SWF DEBUG: Global Post Item: acl=public-read
SWF DEBUG: Global Post Item: AWSAccessKeyId=MY_KEY_ID
SWF DEBUG: Global Post Item: key=blutrotermond.mp3
SWF DEBUG: Global Post Item: success_action_status=201
SWF DEBUG: Global Post Item: policy=MY_ENCODED_POLICY
SWF DEBUG: ReturnUploadStart(): File accepted by startUpload event and readied for upload.  Starting upload to http://my-bucket.s3.amazonaws.com for File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress (OPEN): File ID: SWFUpload_0_0
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 490792. Total: 2167327
SWF DEBUG: Event: uploadProgress: File ID: SWFUpload_0_0. Bytes: 2167327. Total: 2167327
SWF DEBUG: Event: uploadError: HTTP ERROR : File ID: SWFUpload_0_0. HTTP Status: 403.
SWF DEBUG: Event: uploadComplete : Upload cycle complete.

我已经深入了解 AWS-SDK,这就是政策的内容,以及正在签署的内容。对我来说似乎是对的。

{"expiration":"2012-05-02T19:33:31Z",
 "conditions":[{"bucket":"my-bucket"},
               {"key":"blutrotermond.mp3"},
               {"acl":"public-read"},
               {"success_action_status":"201"}]}

所以我不确定如何进一步调试它;SWFUpload 对我隐藏了一些东西,我不确定我的帖子参数/签名有什么问题。任何帮助,将不胜感激。

4

2 回答 2

0

您可以使用WireShark调试 Amazon 响应。

我看到的第一件事是您没有将“x-amz-meta-uuid”参数发布到亚马逊。您可以检查这个PHP 示例并将其移植到 Ruby。实际上我在 .NET 上做过并且效果很好。

于 2012-06-16T08:57:38.927 回答
0

答案原来是 Flash 为所有帖子上传添加了一个字段,需要对帖子中签名的参数进行调整。我在 aws-sdk gem 中添加了对该字段的支持,瞧。

对于调试,可以通过更详细地检查 aws-sdk 抛出的异常来从 AWS 获得错误响应。实际的Net::HTTP响应在某处,并且有一条描述性错误消息,异常消息本身正在吞噬。

请参阅https://github.com/amazonwebservices/aws-sdk-for-ruby/pull/43了解添加对此的支持的代码aws-sdk,以及添加到 post 参数的字段的快速示例。

于 2012-06-18T16:10:45.470 回答