angularjs - 将文件上传到 s3 服务器时出错(请使用 AWS4-HMAC-SHA256)
问题描述
错误信息:不支持您提供的授权机制。请使用 AWS4-HMAC-SHA256。
Angular js http发布请求
url: 'https://abc.s3.amazonaws.com/', //webAPI exposed to upload the file
method: 'POST',
data: {
key: file.name,
AWSAccessKeyId: '*****',
acl: 'private',
Policy: $scope.policy,
Signature: $scope.signature,
"Content-Type": file.type != '' ? file.type : 'application/octet-stream', // content type of the file (NotEmpty)
file: file
Nodejs(签名和策略被发送到角度js中的范围变量)
var secretKey = '*******';
var s3Policy = {
"expiration": "2018-12-01T12:00:00.000Z", // hard coded for testing
"conditions": [
{ "bucket": "*****" },
["starts-with", "$key", ""],
{ "acl": "private" },
["starts-with", "$Content-Type", ""],
{'x-amz-meta-uuid': '14365123651274'},
{'x-amz-credential': '****/20181212/eu-west-3/s3/aws4_request'},
{"x-amz-algorithm" : "AWS4-HMAC-SHA256"},
["content-length-range", 0, 524288000]
],
};
var stringPolicy = JSON.stringify(s3Policy);
var base64Policy = Buffer(stringPolicy, "utf-8").toString("base64");
var signature = crypto.createHmac("sha256", secretKey)
.update(new Buffer(base64Policy, "utf-8")).digest("base64");
var s3Credentials = {
s3Policy: base64Policy,
s3Signature: signature
};
如何解决这个问题?我已经尝试了所有可能的方法,但它不起作用。
解决方案
您正在混合和匹配来自 Signature V4 和 Signature V2 的元素。它们是不兼容的算法。
您的保单看起来像 V4,但您的签名和您发布的表格都是 V2。AWS4-SHA256-HMAC是Signature V4,错误信息表明你的bucket所在区域只支持V4...所以你的代码需要全部使用V4逻辑。
查看https://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-post-example.html
推荐阅读
- python - 张量板 - 错误:已启用跟踪 - 如何解决?
- google-chrome-extension - 我应该请求什么权限才能在特定网站列表上显示模式并有短暂的批准延迟
- java - 不同服务器上的 Apache kafka 生产者和消费者
- c++ - 错误 C2908:显式特化;'' 已经被实例化了
- node.js - RabbitMQ 中的 Node.js“表达式评估为虚假值”错误
- c - 获取整数的负号并将其存储为 char 的最佳方法是什么?
- angularjs - 在sql server Angularjs asp.netmvc中数据更新之前显示记录的搜索方法
- python - 对多个数据帧执行类似的分析
- jboss - 部署自定义 SPI (FreeMarkerLoginFormsProvider) 时出现问题
- matlab-figure - 如何绘制一些数据的灰度及其置信区间