1

I use the below code to get the signed url. I am getting a signed url and once i open the url its downloading the file. But i want a url where i can show the file. Like opening file in a new tab.

I am using aws-sdk package and generate s3 as below

const s3 = new AWS.S3();

s3.getSignedUrl('getObject', {
            Expires: options.expires || 300,
            Bucket: config.awsBucket,
            Key: key,
            // ACL: 'public-read',
            ResponseContentDisposition :'inline;filename=report.pdf'}, 
          function(err, url) {
            if (err) {
                return deferred.reject(err);
            }
            return deferred.resolve(url);
        });

Does anyone know how to generate a url where i can show the file.

Mykola Yashchenko
  • 5,103
  • 3
  • 39
  • 48
  • What is not working, can you try to print the url before resolve and see the signed url? – Kannaiyan Oct 07 '17 at 15:05
  • I get a good aws url but, on openning the url the file is getting downloaded rather than showing the file in browser – Vishesh Madhusudhana Oct 09 '17 at 10:54
  • Possible duplicate of [How do I set Content-Type when uploading to S3 with AWS CLI?](https://stackoverflow.com/questions/29643455/how-do-i-set-content-type-when-uploading-to-s3-with-aws-cli) – Kannaiyan Oct 09 '17 at 13:29
  • Another example of how you can do it with code. https://stackoverflow.com/questions/13979558/saving-an-image-stored-on-s3-using-node-js – Kannaiyan Oct 09 '17 at 13:31

1 Answers1

2

If you didn't set the Content-Type correctly when you uploaded the file, this behavior is to be expected, because the default type is binary/octet-stream, which the browser correctly determines cannot be displayed inline.

You can work around it by setting ResponseContentType in your getSignedUrl() request to the correct value.

The correct type for a PDF file is application/pdf.

Michael - sqlbot
  • 169,571
  • 25
  • 353
  • 427