Can’t upload fie to Quickblox using REST API + AJAX. SignatureDoesNotMatch error

I’m trying to upload file with instruction given in

First i’m creating file, and it always successful, then using params in response of creating file, i’m trying to upload file. And it fails with SignatureDoesNotMatch error. In source code below, i tried to show the whole algorithm. Could you please tell me what am i doing wrong?

// Got file
var file = $('#fileUploader')[0].files[0];
// crearing file in DB
    url: '',
    type: 'POST',
    dataType: 'json',
    contentType: 'application/json',
    headers: {
        'QB-Token': getCookie('QB-Token')
    data: JSON.stringify({
        blob: {
            content_type: file.type,
}).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(){
    }, false);
    xhr.addEventListener("load", function(evt){
    }, false);
    xhr.addEventListener("error", function(){
    }, false);
    xhr.addEventListener("abort", function(){
    }, false);
    // posting request'POST', host, false);

ion (err) {
    console.error('error uploading file', err);

Using code above i’m getting error:
POST 403 (Forbidden)

<?xml version="1.0" encoding="UTF-8"?>
<Message>The request signature we calculated does not match the signature you provided. Check your key and signing method.</Message>
<StringToSignBytes> 6a 41 78 49 6e 31 64 66 51 25 33 44 25 33 44</StringToSignBytes>

in responce

Source: ajax

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.