Download or open in new tab S3 files

Reading Time: 1 minute

When we want to view a file stored in AWS S3 we can either download it and then open it or we can choose to open it in a new tab in the browser.

Solution

The request to S3 must contain ResponseContentDisposition with either “view”, when you want to see the file in browser, or “download”, if you want to download it.

s3.getSignedUrlPromise('getObject', {
  Bucket,
  Key,
  ResponseContentDisposition: 'view' || 'download',
});

Extra tip

Make sure that ContentType is set when you upload the file in S3.

We transform challenges into digital experiences

Get in touch to let us know what you’re looking for. Our policy includes 14 days risk-free!

Free project consultation