我正在尝试使用 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 对我隐藏了一些东西,我不确定我的帖子参数/签名有什么问题。任何帮助,将不胜感激。