我在服务器端生成Pre-Signed URL
并在客户端上传file
。
出于某种原因,我收到来自403 forbidden SignatureDoesNotMatch
的{{1}}错误,但我看不出错误在哪里。
使用AWS
请求postman
,这是我收到的url
:
response
下面我粘贴我的代码:
AngularJS
https://s3-us-west-2.amazonaws.com/my_bucket/uploads/%20VID_20160916_061949.mp4?AWSAccessKeyId=AKIAJV3UP7LBEKPYMLGA&Expires=1474005709&Signature=7KYWah4K%2FEkpdYQR%2FqYDrvCDPgQ%3D
的NodeJS
// My videoData comes as a variable
$http.post(CONFIG.API_URL + '/endpoint1', { filename: videoData[0].name })
.success(function (resp) {
// Perform The Push To S3
$http.put(resp, videoData[0], { headers: {'Content-Type': videoData[0].type} })
.success(function (resp) {
//Finally, We're done
callback(null, 'Upload Done!');
})
.error(function (resp) {
callback("An Error Occurred Attaching Your File");
});
})
.error(function (resp) {
callback("An Error Occurred Attaching Your File");
});
广告管理政策
getSignedUrl: function (filename, callback) {
if (filename) {
AWS.config.update({
accessKeyId: 'my_access_key',
secretAccessKey: 'my_secret_key',
region: 'us-west-2' // I've checked the bucket is correct
});
var s3 = new AWS.S3();
s3.getSignedUrl('putObject', {Bucket: 'my_bucket', Key: 'uploads/' + filename}, function (err, url) {
if (err) {
callback(err);
} else {
callback(url);
}
});
} else {
callback('Error');
}
}
CORS
{
"Version": "2012-10-17",
"Id": "Policy1474002303781",
"Statement": [
{
"Sid": "Stmt1473001308637",
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::my_user:root"
},
"Action": "s3:PutObject",
"Resource": "arn:aws:s3:::my_bucket/uploads"
}
]
}
有人能帮助我吗?
感谢您的建议!