【发布时间】:2021-11-12 07:58:26
【问题描述】:
我正在尝试连接到 azure 容器并保存一个文本文件
const azure = require('azure-storage');
const BlobServiceClient = azure.createBlobService();
const AZURE_STORAGE_CONNECTION_STRING = "my key";
const blobServiceClient = BlobServiceClient.fromConnectionString(AZURE_STORAGE_CONNECTION_STRING);
const containerName = "tempp";
console.log('\nCreating container...');
console.log('\t', containerName);
// Get a reference to a container
const containerClient = blobServiceClient.getContainerClient(containerName);
const blobName = 'test' + uuidv1() + '.txt';
// Get a block blob client
const blockBlobClient = containerClient.getBlockBlobClient(blobName);
console.log('\nUploading to Azure storage as blob:\n\t', blobName);
const data = "message";
const uploadBlobResponse = blockBlobClient.upload(data, data.length);
console.log("Blob was uploaded successfully. requestId: ", uploadBlobResponse.requestId);
我按照文档从 /security + networking/Access Keys 获得了 azure_storage 连接字符串,但是在运行项目时出现错误
Error: Credentials must be provided when creating a service client.
【问题讨论】:
-
我认为您将旧的 SDK 代码 (
azure-storage) 与新的 SDK 代码 (@azure/storage-blob) 混合在一起。
标签: node.js azure express file azure-blob-storage