Azure "blobService is not defined" NodeJS 错误

Azure "blobService is not defined" error with NodeJS

这是我的节点代码,用于连接 Azure Blob 存储并上传 base64 照片以接收 url link 的照片。代码基于 Azure 教程,但不知何故我的 AccountName 和 AccountKey 失败了。我不知道如何设置我的 createBlobService variable.My AccountName 和 AccountKey 只是简单的字符串,即。 "Product"、"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();
                });
            }
        });

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

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

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