【问题标题】:Azure "blobService is not defined" error with NodeJSNodeJS的Azure“未定义blobService”错误
【发布时间】:2017-02-25 23:05:37
【问题描述】:

这是我的节点代码,用于连接 Azure Blob 存储并上传 base64 照片以接收照片的 url 链接。代码基于 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();
                });
            }
        });

【问题讨论】:

  • 您是否能够生成有效的 SAS 令牌,如果是,是否已正确创建 sharedBlobService。因此,这是一个直接的流程,我在这里没有看到问题。这可能只是一些小问题。

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


【解决方案1】:

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

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

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

【讨论】:

  • 如果对你有帮助,可以标记为答案。谢谢。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-01-05
  • 2021-06-25
  • 2021-10-22
  • 2019-09-25
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多