1
我想上傳與http://quickblox.com/developers/Content無法使用REST API + AJAX將fie上傳到Quickblox。 SignatureDoesNotMatch錯誤
首先給我創建文件指令文件,它總是成功的,然後使用PARAMS在創建文件的響應,我試圖上傳文件。並且它會因SignatureDoesNotMatch錯誤而失敗。在下面的源代碼中,我試圖展示整個算法。你能告訴我我做錯了什麼嗎?
// Got file
var file = $('#fileUploader')[0].files[0];
// crearing file in DB
$.ajax({
url: 'http://api.quickblox.com/blobs.json',
type: 'POST',
dataType: 'json',
contentType: 'application/json',
headers: {
'QB-Token': getCookie('QB-Token')
},
data: JSON.stringify({
blob: {
content_type: file.type,
name: file.name
}
})
}).then(function (result) {
// file always successfully created
imgUrl2Upload = result.blob.blob_object_access.params;
// create a FormData instance
var fd = new FormData();
// parsing all params from result.blob.blob_object_access.params
var spltHost = imgUrl2Upload.split('?');
// host before "?"
var host = spltHost[0];
var spltParams = spltHost[1].split('&');
// each param devided by "&"
for (var i = 0; i < spltParams.length; i++) {
var kvpSplt = spltParams[i].split('=');
var key = kvpSplt[0];
var val = kvpSplt[1];
// appending it
fd.append(key, val);
}
// appending file
fd.append('file', file);
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", function(){
console.log('progress');
}, false);
xhr.addEventListener("load", function(evt){
console.log('completed',+ evt.target.responseText);
}, false);
xhr.addEventListener("error", function(){
console.log('failed');
}, false);
xhr.addEventListener("abort", function(){
console.log('aborted');
}, false);
console.log(host);
// posting request
xhr.open('POST', host, false);
xhr.send(fd);
ion (err) {
console.error('error uploading file', err);
});
使用上面的代碼我收到提示: POST http://qbprod.s3.amazonaws.com/ 403(禁止) 與
<?xml version="1.0" encoding="UTF-8"?>
<Error>
<Code>SignatureDoesNotMatch</Code>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<AWSAccessKeyId>AKIAIY7KFM23XGXJ7R7A</AWSAccessKeyId>
<StringToSign>eyJleHBpcmF0aW9uIjoiMjAxNS0wNS0yNlQxNToxMzo0OVoiLCJjb25kaXRpb25zIjpbeyJidWNrZXQiOiJxYnByb2QifSx7ImtleSI6IjAwMzg2YmNhNzFlZjQ3MjE4NDg1YTA5Y2RlMGZmYjUzMDAifSx7ImFjbCI6ImF1dGhlb</StringToSign>
<SignatureProvided>LmeGj%2BRRdWS0LXBF5ZB0V%2B7iIQs%3D</SignatureProvided>
<StringToSignBytes> 6a 41 78 49 6e 31 64 66 51 25 33 44 25 33 44</StringToSignBytes>
<RequestId>D8A12CA856F3FD17</RequestId>
<HostId>i1Po/EpITRbloN+</HostId>
</Error>
在性反應
請描述一下 – Saif