我想创建一个带有自定义内容类型的签名 url,我正在尝试这样做:
s3.getSignedUrl('getObject', {Bucket: AWS_BUCKET_NAME, Key: 'myObjectsKey', ContentType: 'image/png'}, function (err, url) {
console.log(err, url);
});
但是,这给出了错误:
{ [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) }
,我觉得这很奇怪,因为这里有关于签署请求的文档:
http://docs.aws.amazon.com/AmazonS3/latest/dev/RESTAuthentication.html
声明签名是由散列法制成的:
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;
,它允许您提供内容类型。
这是怎么回事?
最佳答案
这一定已经更新,因为您现在可以执行此操作,只需使用 ResponseContentType
而不是 ContentType
。查看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);
});
我什至用 Saz files 测试过它效果很好。
关于javascript - 在 s3 aws 中为对象创建签名 url 时如何设置内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27539920/