为什么这个SWFUpload - > Presigned Post到S3设置不起作用? (导轨)

时间:2012-05-02 18:46:20

标签: ruby-on-rails amazon-s3 swfupload

我正在尝试使用SWFUpload和AWS-SDK对S3进行预先发布的帖子。长话短说,它不起作用。

我这样设置了SWFUpload(原谅coffeescript):

@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隐藏了我的内容,我不确定我的帖子参数/签名有什么问题。任何帮助将不胜感激。

2 个答案:

答案 0 :(得分:0)

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

我看到的第一件事是您没有将“x-amz-meta-uuid”参数发布到亚马逊。您可以检查此PHP example并将其移植到Ruby。实际上我在.NET上做了很好的工作。

答案 1 :(得分:0)

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

对于调试,可以通过检查aws-sdk引发的异常以及更多细节来从AWS中获取错误响应。实际的Net::HTTP响应位于某处,并且有一条描述性错误消息,表明异常消息本身正在吞咽。

有关将此支持添加到aws-sdk的代码,请参阅https://github.com/amazonwebservices/aws-sdk-for-ruby/pull/43,以及要添加到帖子参数的字段的快速示例。