Backblaze S3 兼容 API - 预签名 URL - 节点 AWS SDK 不工作
Backblaze S3 Compatible API - Pre-signed URLs - Node AWS SDK not working
我正在尝试让新的 Backblaze 兼容 S3 API 与预签名 URLs
一起使用
我用来生成 URL () 的代码:
const aws = require('aws-sdk');
const s3 = new aws.S3({
accessKeyId: 'XXX',
secretAccessKey: 'XXX',
endpoint: 's3.us-west-002.backblazeb2.com',
});
const myBucket = 'bucket-name'
const myKey = 'file-name.pdf'
const signedUrlExpireSeconds = 60 * 5 // I know this is not supported yet.
const url = s3.getSignedUrl('getObject', {
Bucket: myBucket,
Key: myKey,
Expires: signedUrlExpireSeconds
})
console.log(url)
正确生成Url:
https://BUCKETNAME.s3.us-west-002.backblazeb2.com/BUCKETKEY?AWSAccessKeyId=XXX&Expires=XXX&Signature=XXX
但是当转到浏览器中生成的 URL 时,我得到以下错误:
<Error>
<Code>InvalidRequest</Code>
<Message>Invalid request parameter received: AWSAccessKeyId</Message>
</Error>
我做错了什么?
刚刚找到解决方法。默认签名版本似乎是带有 AWS SDK 的 v2。只需确保将签名版本添加到 S3 初始化中即可。在上面的例子中:
const url = s3.getSignedUrl('getObject', {
Bucket: myBucket,
Key: myKey,
Expires: signedUrlExpireSeconds
signatureVersion: 'v4'
})
更多信息:
https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html
我正在尝试让新的 Backblaze 兼容 S3 API 与预签名 URLs
一起使用我用来生成 URL (
const aws = require('aws-sdk');
const s3 = new aws.S3({
accessKeyId: 'XXX',
secretAccessKey: 'XXX',
endpoint: 's3.us-west-002.backblazeb2.com',
});
const myBucket = 'bucket-name'
const myKey = 'file-name.pdf'
const signedUrlExpireSeconds = 60 * 5 // I know this is not supported yet.
const url = s3.getSignedUrl('getObject', {
Bucket: myBucket,
Key: myKey,
Expires: signedUrlExpireSeconds
})
console.log(url)
正确生成Url:
https://BUCKETNAME.s3.us-west-002.backblazeb2.com/BUCKETKEY?AWSAccessKeyId=XXX&Expires=XXX&Signature=XXX
但是当转到浏览器中生成的 URL 时,我得到以下错误:
<Error>
<Code>InvalidRequest</Code>
<Message>Invalid request parameter received: AWSAccessKeyId</Message>
</Error>
我做错了什么?
刚刚找到解决方法。默认签名版本似乎是带有 AWS SDK 的 v2。只需确保将签名版本添加到 S3 初始化中即可。在上面的例子中:
const url = s3.getSignedUrl('getObject', {
Bucket: myBucket,
Key: myKey,
Expires: signedUrlExpireSeconds
signatureVersion: 'v4'
})
更多信息: https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html