Hi, i need some help with the following problem.
i’m working in a react app with version node 14.
I want to use r2 for file storage but when i try put object and others methods i have the same problem.
“The request signature we calculated does not match the signature you provided. Check your secret access key and signing method.”
My running code below:
When i do
await s3.getSignedUrlPromise('putObject', { Bucket: 'aya-app', Key: 'dog.png', Expires: 3600 })
Response:
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your secret access key and signing method. </Message>
</Error>
But when i do
await s3.getSignedUrlPromise('listBuckets', {})
The response is the answer is satisfactory
<ListBucketResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>aya-app</Name>
<IsTruncated>false</IsTruncated>
<MaxKeys>1000</MaxKeys>
<KeyCount>0</KeyCount>
</ListBucketResult>
I already checked: -Access key id -SecreteAccesKey. - I tried with ‘signature:v2 /v3/v4’
My complete code below:
import S3 from 'aws-sdk/clients/s3.js';
const s3 = new S3({
endpoint: `https://xxxxxxxxxx.r2.cloudflarestorage.com/aya-app`,
accessKeyId: "xxxxxxx",
secretAccessKey: "xxxxxxx",
signatureVersion: 'v4',
region: 'auto',
version: '2006-03-01',
});
async function testR2() {
let listBuckets = await s3.getSignedUrlPromise('listBuckets', {})
let putObject = await s3.getSignedUrlPromise('putObject', { Bucket: 'aya-app', Key: 'dog.png', Expires: 3600 })
console.log("listBuckets", listBuckets, "putObject", putObject)
}
await testR2()