Azure的BLOB sasToken"签名不匹配" [英] Azure blob sasToken "Signature did not match"

查看:834
本文介绍了Azure的BLOB sasToken"签名不匹配"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图用上传到蔚蓝的Blob存储的图像 createBlockBlobFromLocalFile 。我创建了 sasToken 像什么的 Azure的存储节点指示的此处。这里是我的code上传

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.

在这里输入的形象描述

修改
响应消息

推荐答案

通常,当我们出现此问题,这意味着sasToken内容这么想的匹配,我们在Azure存储。

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

和在我的身边,你的code正常工作。所以,请仔细检查是否已创建了一个名为容器资源您Blob存储。

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

由于在我的身边,我只能重现您的问题时,我上传一个blob到Azure存储没有一个容器创造了previously。

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

这篇关于Azure的BLOB sasToken"签名不匹配"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆