Question

"Signature Does Not Match" when putting to presigned spaces upload url

I am using the aws-sdk in Node.js to generate a presigned putObject upload url for use with DigitalOcean Spaces. The url gets generated just fine, however when I try putting to it using a REST client, I get a SignatureDoesNotMatch error. Below is the code I am using to generate the presigned url (from within a Google Cloud Function):

var AWS = require('aws-sdk');
AWS.config.loadFromPath('./credentials.json');
var s3 = new AWS.S3({params: {Bucket: 'bucket-name'}});

exports.requestUploadUrl = function requestUploadUrl(req, res) {
  var key = 'some-predefined-key';
  s3.getSignedUrl('putObject', {Bucket: 'bucket-name', Key: key}, function (err, url) {
    res.send(url);
  });
}

I am getting this sort of response when I try posting to the presigned url:

<?xml version="1.0" encoding="UTF-8" ?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<RequestId>tx000000000000000664ed3-0059eeef91-3777b-nyc3a</RequestId>
<HostId>3777b-nyc3a-nyc</HostId>
 </Error>
Show comments

Submit an answer


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Accepted Answer

So the reason this wasn’t working is the content type MUST be specified when generating the presigned URL and specified once again by the client when it connects, and they must exactly match. Once I specified application/octet-stream everything worked

@anoopg your problem is a bit more simple. The accessKeyId is the name you gave your spaces access key, and the secretAccessKey is simply the value of the key. You don’t need to use a personal access token at all for this.

Its sad that AWS give wrong examples in its documentation. When i first tried python example even the signing key creation method was faulty. For your problem i would suggest you replicate their Requests even use same AccessKeyId and secretacesskey as given in examples. Then compare the signature and payload hash. If it doesn’t match than start debugging. 2- I think aws multipart request doesn’t work with presigned urls with REST. Either you have to use AWS SDK or use Authorization Header.

Thanks Sahil DESWAL Creator of bluntfox.com

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.