Skip to content Skip to sidebar Skip to footer

Azure Storage Authorization Failed Or Format Is Wrong

Good day everybody, I'm stuck with authorization on azure storage. When I am uploading only one file(blob) I put SAS key in the url and everything works fine. But when I need to cr

Solution 1:

If you're using Shared Access Signature (SAS), then you don't need to specify the Authorization header as the SAS token contains this value. You also need not define x-ms-version and x-ms-date headers. What you do need to include is x-ms-blob-type request header and set its value to BlockBlob.

What you would need to do is take the SAS token and append that to your URL (please make sure that you don't include the ? in the SAS Token.

Assuming you're storing the Sas Token from portal in a variable called sasToken, your code would be:

$scope.upload = function (file) {
    blockId = blockId + 1;
    Upload.upload({
        url: "https://MYSTORAGENAME.blob.core.windows.net/kont1/"+ file.name + "?comp=block&blockid=" + blockId + "&" + sasToken,
        method: 'PUT',
        resumeChunkSize: '40MB', // upload in chunks of specified sizeheaders: {
            'Content-type': 'multipart/form-data',
            'Authorization': 'SharedKey' + "MYSTORAGENAME:iDrJ7OuggJ8uoIn5olNDeOvSAoMrpqckl5mUaT5/H/w=",
            'x-ms-version': '2015-12-11',
            'x-ms-date': newDate().toUTCString()
            },
        data: {file: file}
    }).then(function (resp) {
        console.log('Success ' + resp.config.data.file.name + 'uploaded. Response: ' + resp.data);
    }, function (resp) {
        console.log('Error status: ' + resp.status);
    }, function (evt) {
        var progressPercentage = parseInt(100.0 * evt.loaded / evt.total);
        console.log('progress: ' + progressPercentage + '% ' + evt.config.data.file.name);
    });
};

Post a Comment for "Azure Storage Authorization Failed Or Format Is Wrong"