I'm currently generating a pre-signed url to upload an object to my AWS s3 bucket
const signedUrl = await s3.getSignedUrl('putObject', params);
Here is my params object:
const params = {
Bucket: 'mybucket',
Key: `mybucketpost-${Math.ceil(Math.random() * 10 ** 10)}.png`,
ContentType: 'image/png',
Metadata: {
ContentType: 'image/png',
},
Expires: 36000
}
I'm able to successfully generate a presigned URL and upload an object to my bucket, but when I'm trying to access the object using the s3.getSignedUrl method, the object gets downloaded instead of the png image opening up in my browser tab. Now with all the research I've done, I understand why that's happening. That's because the system-defined object metadata Content-Type for my object is still binary/octet-stream.
Even though I've attempted to change the Content-Type for the object I'm generating the presigned url for to image/png, it gets added as a user-generated metadata for the object x-amz-meta-contenttype: image/png.
So in my AWS console, the meta-data for my uploaded object are:
System defined Cache-Control no-cache
System defined Content-Type binary/octet-stream
User defined x-amz-meta-contenttype image/png
and unfortunately, this does not solve the issue of loading up the image in the browser tab.
I've tried changing the System defined meta-data Content-Type for an object directly through the AWS console to image/png and as expected, the object (png) opens up in my browser tab using the object URL, but I've not been able to find a way to change System Defined meta-data Content-Type using the AWS SDK for Node.js while generating the presigned URL using the putObject property. Need your help with the same. Thanks!