简体   繁体   English

使用 aws-sdk 的 AWS S3 签名 URL 失败并显示“AuthorizationQueryParametersError”

[英]AWS S3 signed URLs with aws-sdk fails with “AuthorizationQueryParametersError”

I am trying to create a pre-signed URL for a private file test.png on S3.我正在尝试为 S3 上的私有文件 test.png 创建一个预先签名的 URL。 My code:我的代码:

var AWS = require('aws-sdk'); 

AWS.config.region = 'eu-central-1';

const s3 = new AWS.S3();

const key = 'folder/test.png';
const bucket = 'mybucket';
const expiresIn = 2000; 

const params = {
    Bucket: bucket,
    Key: key,
    Expires: expiresIn,
};
console.log('params: ', params);
console.log('region: ', AWS.config.region);

var url = s3.getSignedUrl('getObject', params);
console.log('url sync: ', url);

s3.getSignedUrl('getObject', params, function (err, urlX) {
    console.log("url async: ", urlX);
});

which returns a URL in the console.它在控制台中返回一个 URL。 When I try to access it, it shows当我尝试访问它时,它显示

<Error>
<Code>AuthorizationQueryParametersError</Code>
<Message>
Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.
</Message>
<RequestId>97377E063D0B1D09</RequestId>
<HostId>
6GE7EdqUvCEJis+fPoWR0Ffp2kN9Mlql4gs+qB4uY3hA4qR2wYrImkZfv05xy4XVjsZnRDVN63s=
</HostId>
</Error>

I am totally stuck and would really appreciate some idea on how to solve it.我完全被困住了,真的很感激一些关于如何解决它的想法。

i tested your code.我测试了你的代码。 i only made modifications to key and bucket .我只对keybucket进行了修改。 it works.它有效。 may i know the aws sdk version you are using and the nodejs version you are using?我可以知道您使用的 aws sdk 版本和您使用的 nodejs 版本吗? my test was executed on nodejs 8.1.2 and aws-sdk@2.77.0 .我的测试是在 nodejs 8.1.2 和aws-sdk@2.77.0上执行的。

I was able to reproduce your error when I executed curl.当我执行 curl 时,我能够重现您的错误。

curl url (wrong) -> <Error><Code>AuthorizationQueryParametersError</Code><Message>Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.</Message> curl url (错误)-> <Error><Code>AuthorizationQueryParametersError</Code><Message>Query-string authentication version 4 requires the X-Amz-Algorithm, X-Amz-Credential, X-Amz-Signature, X-Amz-Date, X-Amz-SignedHeaders, and X-Amz-Expires parameters.</Message>

curl "url" (worked) curl "url" (工作)

if you curl without the double quotes, ampersand is interpreted by the shell as a background process.如果在没有双引号的情况下卷曲,shell 会将 & 符号解释为后台进程。

Alternatively, you could try pasting the generated link in a browser.或者,您可以尝试在浏览器中粘贴生成的链接。

Hope this helps.希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM