Home > other >  How to view the image in the browser with presigned URL
How to view the image in the browser with presigned URL

Time:08-24

I am using AWS SDK to sign the URL for viewing the object in the Browser tab on getting it. But when I open the URL with window.open(url) -> Its downloading the file.

var s3 = new AWS.S3();
const url = await s3.getSignedUrlPromise('getObject', {
    Bucket: process.env.S3_BUCKET_NAME,
    Key: fileKey,
    Expires: 90
   })

Is there a way to view it from the browser instead of downloading it.

CodePudding user response:

It's downloading the file because you don't have the correct MIME type set on the object in S3. You need to set the MIME type of the image in the ContentType attribute of the S3 object.

  • Related