NodeJS的Azure“blobService未定义”错误

时间:2016-10-17 04:05:07

标签: node.js azure azure-storage-blobs

这是我的节点代码,用于连接Azure Blob存储和上传base64照片以接收照片的网址链接。代码基于Azure教程,但我的AccountName和AccountKey以某种方式失败。我无法弄清楚如何设置我的createBlobService变量。我的AccountName和AccountKey只是简单的字符串即。 “产品”,“Base64KeyProvidedByAzure”

请帮忙吗?

帐户名,帐户密钥和容器名称只是虚拟字符串。

var blobSvc = azure.createBlobService('AccountName', 'AccountKey');


        blobService.createContainerIfNotExists('containerName', {
            publicAccessLevel: 'blob'
        }, function(error, result, response) {
            if (!error) {
                // if result = true, container was created.
                // if result = false, container already existed.
                var sharedAccessPolicy = {
                    AccessPolicy: {
                        Permissions: azure.BlobUtilities.SharedAccessPermissions.WRITE,
                    }
                };
                var sharedAccessSignatureToken = blobSvc.generateSharedAccessSignature('ContainerName', req.params.filename, sharedAccessPolicy);
                var sharedBlobService = azure.createBlobServiceWithSas(blobSvc.host, sharedAccessSignatureToken);

                sharedBlobService.createBlockBlobFromText('eats', req.params.name, req.params.file,
                    {
                        contentType: 'image/jpeg',
                        contentEncoding: 'base64'
                    },

                    function(error, result, response) {
                    if (error) {
                        res.send(error);
                        return;
                    }


                    var msg = "Photo Uploaded successfully";
                    helpers.success(res, next, msg, 200);
                    return next();
                });
            }
        });

1 个答案:

答案 0 :(得分:1)

您创建了一个blob服务实例并在第1行中分配给blobSvc

  

var blobSvc = azure.createBlobService('AccountName', 'AccountKey');

但是,您使用blobService来调用SDK中的函数。所以它抛出blobService is not defined异常。