I want to create a signed url with a custom content-type, I was trying this:
s3.getSignedUrl('getObject', {Bucket: AWS_BUCKET_NAME, Key: 'myObjectsKey', ContentType: 'image/png'}, function (err, url) {
console.log(err, url);
});
however this gives the error:
{ [UnexpectedParameter: Unexpected key 'ContentType' found in params]
message: 'Unexpected key \'ContentType\' found in params',
code: 'UnexpectedParameter',
time: Thu Dec 18 2014 01:38:19 GMT-0400 (AST) }
Which I find strange because the documentation on signing requests here:
http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
states that a signature is made from hashing:
Signature = URL-Encode( Base64( HMAC-SHA1( YourSecretAccessKeyID, UTF-8-Encoding-Of( StringToSign ) ) ) );
StringToSign = HTTP-VERB + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Expires + "\n" +
CanonicalizedAmzHeaders +
CanonicalizedResource;
Which allows you to give a content-type. Does anyone know what's going on?
This must have been updated because you can now do this, just use ResponseContentType
rather than ContentType
. Check out the GET Object Docs.
const params = {
Bucket: bucket,
Key: key,
Expires: 60,
ResponseContentType: 'image/png'
};
s3.getSignedUrl('getObject', params, function (err, url) {
if (url) callback(null, url);
else callback(err, null);
});
I tested it even with Saz files and it worked great.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With