The request signature we calculated does not match the signature you provided. Check your secret access key and signing method

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()
1 Like

Hitting a similar wall. Put the R2 endpoint, keys, and v4 signature in an app that works with S3, but keep getting Aws::S3::Errors::SignatureDoesNotMatch errors on every PUT. Did you make any progress?

There are different problems with cors and preflight cors. I was able to fix most of it.First of all, you have to config bucket cors.What worked best for me was doing it from Postman.

You must follow these steps for config CORS.

I also pass you what I wrote in the body of postman request.

<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <CORSRule>
        <AllowedMethod>GET</AllowedMethod>
        <AllowedMethod>PUT</AllowedMethod>
        <AllowedMethod>HEAD</AllowedMethod>
        <AllowedHeader>content-type</AllowedHeader>
        <AllowedOrigin>*</AllowedOrigin>
    </CORSRule>
</CORSConfiguration>

**AllowHeader doesn’t support ‘*’ and has capitalization issues so you have to specify each header you need and lowercase it as content-type.

Below is my complete code to upload a file

        let putObject = await s3.getSignedUrlPromise('putObject', {
            Bucket: <bucket-name>,
            Key: <file-name>,
            Expires: 3600,
        })
        await fetch(putObject, {
            method: 'PUT',
            body: file,
        }).then((response) => {
            console.log(response);
        }).catch((error) => {
            console.log(error);
        })

here, more explanations of what is going wrong in R2
https://discord.com/channels/595317990191398933/940663374377783388/1039142397973635174

my current problem is that i am not able to use headObject…