Dev1ce
Dev1ce

Reputation: 5944

How to upload a file from Postman using AWS S3 signed url?

I want to achieve the following -
1. Generate a signed URL
2. Upload a file (image.jpg), to the URL using Postman

I am using AWS Node SDK to create the URL,
Following is the code -

const AWS = require('aws-sdk');

AWS.config.update({
    region: 'us-east-1'
});

const s3 = new AWS.S3();

var presignedPUTURL = s3.getSignedUrl('putObject', {
    Bucket: 'some-bucket',
    Key: 'test/image.jpg',
    Expires: 3600
});

console.log(presignedPUTURL);

The code creates an URL like -

https://some-bucket.s3.amazonaws.com/test/image.jpg?AWSAccessKeyId=ABCDxxx&Expires=1572339646&Signature=someSignaturexxx

Here is the Postman response -

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

Postman call - enter image description here
------------------------------------------------------------------------------ enter image description here

I tried following this -
https://medium.com/@aidan.hallett/securing-aws-s3-uploads-using-presigned-urls-aa821c13ae8d

I also tried various combinations, of the Key in code and filename to upload having the same name,
different Content-Type combination,
But no luck.

Upvotes: 8

Views: 8406

Answers (1)

Ahmed Mehanna
Ahmed Mehanna

Reputation: 141

Postman added hidden headers. If I remove the Content-Type header, The Put request will work as expected.

enter image description here

Upvotes: 4

Related Questions