s3浏览器上传,规范或策略桶?

时间:2017-03-05 05:36:37

标签: ruby-on-rails amazon-web-services amazon-s3

最新sigv4 s3浏览器上传帖子的文档 - http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html - 表明我需要使用x-amz-signaturex-amz-credentialpolicy

如果我尝试这样做,则会收到错误消息,说明我错过了AWSAccessKeyId,文档中没有提到x-amz-signaturesignature需要hmac.new(signing_key, (string_to_sign).encode('utf-8'), hashlib.sha256).hexdigest()

要签名的字符串:

我是否应该在上面执行base64存储桶策略文档,或者我应该采用规范方法,例如发布到dynamoDB的python帖子 - http://docs.aws.amazon.com/general/latest/gr/sigv4-signed-request-examples.html#sig-v4-examples-post

特征:

规范使用hmac hexdigest Base64.encode64(OpenSSL::HMAC.digest('sha256', signaturekey, @policy))

上面的上传文档使用hmac和base64:OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha256'), key, value)

hood of the ruby sdk下,看起来他们正在使用非hmac hexdigest:{"expiration":"2017-03-06T20:13:51Z", "conditions":[ {"bucket":"example-development"}, {"x-amz-credential":"AKIAIVVIZJHOBCBAB5CA/20170305/us-west-2/s3/aws4_request"}, {"x-amz-algorithm":"AWS4-HMAC-SHA256"}, {"x-amz-date":"20170305T000000Z"} ] }

上传到s3需要哪种方法?

FWIW,我使用带有Rails的SPA作为API,所以我很遗憾无法访问任何rails视图助手。

我发布了一个关于我的代码yesterday的问题,很遗憾地显示了一个使用rails view helpers的链接

编辑:

政策发送的内容:

Policy:"eyJleHBpcmF0aW9uIjoiMjAxNy0wMy0wNlQyMDoxOTowN1oiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJ3YXlkb3BlLWRldmVsb3BtZW50In0seyJ4LWFtei1jcmVkZW50aWFsIjoiQUtJQUlWVklaSkhPQkNCQUI1Q0EvMjAxNzAzMDUvdXMtd2VzdC0yL3MzL2F3czRfcmVxdWVzdCJ9LHsieC1hbXotYWxnb3JpdGhtIjoiQVdTNC1ITUFDLVNIQTI1NiJ9LHsieC1hbXotZGF0ZSI6IjIwMTcwMzA1VDAwMDAwMFoifV19"
X-Amz-Signature:"Cqjvo9aYCrb8PYHD+mUDjlOwKUzTpsI4d5/oycFAUBA="
key:"uploads/photo/photo/126/photo.jpg"
x-amz-algorithm:"AWS4-HMAC-SHA256"
x-amz-credential:"AKIAIVVIZJHOBCBAB5CA/20170305/us-west-2/s3/aws4_request"
x-amz-date:"20170305T000000Z"

表格发送的内容:

....
table = Texttable(max_width = 6000)
table.set_precision(20)
....

存储桶策略和CORS包含零条件。

1 个答案:

答案 0 :(得分:0)

使用s3浏览器上传时,要签名的字符串应为bucket config:http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-UsingHTTPPOST.html

按照页面底部的链接进行操作。