Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 907
Ani Avatar asked Oct 29 '19 08:10

Ani


People also ask

How do I upload Postman app to Amazon S3?

Go to Chrome > Settings, search for SSL (chrome://settings/search#ssl) and click on Manage certificates. Use the link again in Postman and it will work.

How do I upload a pre-signed URL?

When you create a presigned URL, you must provide your security credentials and then specify a bucket name, an object key, an HTTP method (PUT for uploading objects), and an expiration date and time. The presigned URLs are valid only for the specified duration.

How do I get an S3 signed URL?

Sign in to the AWS Management Console and open the Amazon S3 console at https://console.aws.amazon.com/s3/ . In the Buckets list, choose the name of the bucket that contains the object that you want a presigned URL for. In the Objects list, select the object that you want to create a presigned URL for.


1 Answers

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

enter image description here

like image 115
Ahmed Mehanna Avatar answered Nov 15 '22 02:11

Ahmed Mehanna