Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

136
Views
Uploading to S3 from browser using signed upload URL fails

I'm trying to upload a file to S3 directly from browser. For this, I'm generating a signed upload URL on my server.

When I try to upload a file to the generated url from the browser using

var xhr = new XMLHttpRequest();
xhr.open('PUT', signedUrl);     
xhr.send(file);

I get the following error

<Error>
  <Code>
    SignatureDoesNotMatch
  </Code>
  <Message>
    The request signature we calculated does not match the signature you provided. Check your key and signing method.
  </Message>
  ...
</Error>

I can upload to the signed URL using curl with the following command

curl -T <file> -X PUT '<signed-url>'

The browser is sending my request as multipart-form data which is causing the problem. How do I fix the issue?

I'm generating the signed URL using the following code

var params = {
    Bucket: bucket, 
    Key: s3Key,
    ACL: "authenticated-read",
    Expires: 600
};

S3.getSignedUrl('putObject', params, (err, data) => {
    const returnData = {
        url: data
    };
    reply(returnData);
});

Edit: Just to be clear, I have allowed all origins to send PUT requests in bucket CORS configuration.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Okay, the problem was that Content-Type was being sent by the browser in the request header but the signed url wasn't being generated for the content type. Instead of this

var params = {
    Bucket: bucket, 
    Key: s3Key,
    ACL: "authenticated-read",
    Expires: 600
};
S3.getSignedUrl('putObject', params, ...);

I did this

var params = {
    Bucket: bucket, 
    Key: s3Key,
    ACL: "authenticated-read",
    Expires: 600,
    ContentType: require('mime').lookup(filename)
};
S3.getSignedUrl('putObject', params, ...);

and it worked!

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!