Azure blob sasToken “Signature did not match”

情到浓时终转凉″ 提交于 2019-12-12 01:37:00

问题


I was trying to upload an image to azure blob storage using createBlockBlobFromLocalFile. And I created the sasToken like what azure-storage-node instructed here. Here's my code for upload.

module.exports = function(params) {

var config = require('../../config/secrets');
var fs = require('fs');
var azure = require('azure-storage');
var controllers = {};

var blobSvc = azure.createBlobService(config.BLOB_LINK, config.BLOB_KEY);


controllers.upload = function (req, res, next){

    var fstream;
    req.pipe(req.busboy);

    var startDate = new Date();
    var expiryDate = new Date(startDate);
    expiryDate.setMinutes(startDate.getMinutes() + 100);
    startDate.setMinutes(startDate.getMinutes() - 100);

    var sharedAccessPolicy = {
        AccessPolicy: {
            Permissions: azure.BlobUtilities.SharedAccessPermissions.WRITE,
            Start: startDate,
            Expiry: expiryDate
        }
    };

    req.busboy.on('file', function (fieldname, file, filename) {

        fstream = fs.createWriteStream(__dirname + '/upload/' + filename);
        file.pipe(fstream);
        fstream.on('close', function () {

            var sharedAccessSignatureToken = blobSvc.generateSharedAccessSignature('resources', filename, sharedAccessPolicy);
            var sharedBlobService = azure.createBlobServiceWithSas(blobSvc.host, sharedAccessSignatureToken);
            console.log("sas", sharedAccessSignatureToken);

            sharedBlobService.createBlockBlobFromLocalFile(
                    'resources',
                    filename,
                    fstream.path,
                    function(error, result, response) {
                        if (error) {
                            res.send(error);
                            return;
                        }
                        res.send(result);
                    });
        });
    });
}

return controllers;

};

But Im getting this error on my frontend.

EDIT response message


回答1:


Usually, when we occur this issue, which means the sasToken content dosen't match the resource we request on Azure Storage.

And on my side, your code works fine. So please double check whether you have created the container named resources on your Blob Storage.

As on my side, I only can reproduce your issue when I upload a blob to Azure Storage without a container has created previously.



来源:https://stackoverflow.com/questions/36263130/azure-blob-sastoken-signature-did-not-match

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!