我想用自定义内容类型创建一个签名的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
指出签名是通过哈希生成的:
签名= 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文件,我也进行了测试,效果很好。