我正在使用Phonegap捕获视频文件并将其上传到Amazon S3和Amazon S3 SDK,以获取请求的预签名网址。在本地使用PHP服务器时捕获和上传工作正常,从Amazon获取预先签名的URL也没有问题。然而,当我结合所有这些东西时:尝试使用生成的预签名网址将捕获的视频上传到亚马逊,我得到“我们计算的请求签名与您提供的签名不匹配。”
以下是获取预签名网址并上传到亚马逊的方法:
uploadFile: function (file) {
var //path = file.fullPath,
path = file.localURL,
name = file.name,
type = file.type;
var s3 = new AWS.S3(),
s3_params = {
Bucket: 'BUCKET_NAME',
Key: name,
Expires: 6000
//ContentType: type,
//ACL: 'public-read'
};
s3.getSignedUrl('putObject', s3_params, function(err, data){
if(err){
console.log(err);
}
else{
var ft = new FileTransfer(),
url = encodeURI(data);
console.log(data);
ft.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
console.log(progressEvent.loaded / progressEvent.total);
} else {
console.log(progressEvent);
}
};
ft.upload(
path,
url,
function(result) {
console.log('Upload success: ' + result.responseCode);
console.log(result.bytesSent + ' bytes sent');
},
function(error) {
console.log('Error uploading file ' + path + ': ' + error.code);
},
{
httpMethod : 'PUT',
fileName : name,
mimeType : type,
chunkedMode : false,
headers: {
'Content-Type' : type,
'x-amz-acl' : 'public-read'
}
}
);
}
});
}
我做错了吗?
我知道有关此主题的SO有很多问题/答案,但似乎没有什么对我有用......
请在此处查看完整的测试应用: https://github.com/terreb/Phonegap-Media-Capture-S3-Upload
请指教!
答案 0 :(得分:0)
不太确定,但可能会解决问题。
根据their documentation您可能需要添加' ServerSideEncryption'在 s3_params 中就像这样
s3_params = {
Bucket: 'BUCKET_NAME',
Key: name,
Expires: 6000
ServerSideEncryption: 'AES256'
};
希望这会有所帮助
答案 1 :(得分:0)
好吧,好像我发现了问题:getSignedUrl返回ALREADY编码的网址。
纠正方法:
WITH MEMBER Time.T1 AS 'SUM([Time].&[TY].&[0]:[Time].&[TY].&[11])'
MEMBER Time.T2 AS 'SUM([Time].&[TY].&[0]:[Time].&[TY].&[11])'
MEMBER Measures.Col1 AS '(Scenario.&[PO], [T1], [GNAm])'
MEMBER Measures.Col2 AS '(Scenario.&[ACFC], [T2], [GNAm])'
MEMBER Measures.Diff AS '[Col2] - [Col1]'
MEMBER Measures.Perc AS 'IIF([Col1] = 0, [Col1], [Diff] / [Col1])', FORMAT_STRING = '#0.00%'
SELECT {[Col1], [Col2], [Diff], [Perc]} on Columns, Descendants([Account].[Account].[Expenses]) on Rows
FROM DS_GNA
WHERE (&[44026-90],&[010000])
}