我有以下從第三方應用aws s3 api
終點403禁止對於Amazon S3把API上傳文件中的Rails應用程序
https://xxx.s3.amazonaws.com/uploads/74d75512c28b49358846f959bd798536?Signature=lxBIZJD7DN4QK3LPmsHxR7D2eTA%3D&Expires=1506108780&AWSAccessKeyId=AKIAJG6Z6A5TUL7ULPXA
我試圖讓一個PUT request
這個網址到upload an File
,但總能得到以下error
#<Net::HTTPForbidden 403 Forbidden readbody=true>
更新這裏是響應主體
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>
The request signature we calculated does not match the
signature you provided. Check your key and signing method.
</Message>
<AWSAccessKeyId>AKIAJG6Z6A5TUL7ULPXA</AWSAccessKeyId>
<StringToSign>
PUT
application/xml
1506144576
/xxx/uploads/93a64f8081804604be917b4185c5ed58
</StringToSign>
<SignatureProvided>8pwtC2vtN4LuOwGc887AlT2ZnUc=</SignatureProvided>
<StringToSignBytes>50 55 </StringToSignBytes>
<RequestId>B2B18369BA23A92F</RequestId>
<HostId>YCtjOJsfskITKxjW96ouZq1BV=</HostId>
</Error>
如果我inspect
response
它顯示以下data
,但不明白這是什麼問題?沒有其他線索,任何人都可以幫助將不勝感激。
{
"x-amz-request-id" => [
[0] "385D5CADFE6175FC"
],
"x-amz-id-2" => [
[0] "4uD51Gb/rJy0QooQVmF25Qbp0E568bB9v1P4Grg9CTM2dJ/Iiccad/IyuuEnWDphlGZrr8ZUnQw="
],
"content-type" => [
[0] "application/xml"
],
"transfer-encoding" => [
[0] "chunked"
],
"date" => [
[0] "Fri, 22 Sep 2017 19:28:01 GMT"
],
"server" => [
[0] "AmazonS3"
]
}
我運行下面的代碼片段
uri = URI.parse(aws_api_end_point)
request = Net::HTTP::Put.new(uri)
request.body = File.read(file_path)
request.content_type = 'application/xml'
http = Net::HTTP.start(uri.host, uri.port, :use_ssl => true)
response = http.request(request)
注::我沒有使用任何AWS SDK。
*如果我檢查響應,它顯示下列數據*沒有什麼有趣的東西,那裏。但是,如果您可以提取它並向我們顯示,那麼在錯誤響應中也可能有用** body **。 –
謝謝@ Michael-sqlbot,我已經更新了響應正文的問題,它顯示簽名不匹配。但我想知道第三方是否發給我們錯誤的簽名。 –