I am trying to get the new Backblaze compatible S3 API to work with Pre-signed URLs
Code that I am using to generate the URL (original source):
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)
The Url is correctly generated:
https://BUCKETNAME.s3.us-west-002.backblazeb2.com/BUCKETKEY?AWSAccessKeyId=XXX&Expires=XXX&Signature=XXX
But when going to the generated URL inside the Browser I get the follwing Error:
<Error>
<Code>InvalidRequest</Code>
<Message>Invalid request parameter received: AWSAccessKeyId</Message>
</Error>
What am I doing wrong?
Just found out how to fix this. The default Signature version seems to be v2 with the AWS SDK. Just make sure to add the signature version to the S3 initialization. Inside the example above:
const url = s3.getSignedUrl('getObject', {
Bucket: myBucket,
Key: myKey,
Expires: signedUrlExpireSeconds
signatureVersion: 'v4'
})
More Info: https://docs.aws.amazon.com/AmazonS3/latest/dev/UsingAWSSDK.html