@azure/storage-blob与最新的azure存储模拟器不兼容

brc7rcf0  于 2023-05-18  发布在  其他
关注(0)|答案(1)|浏览(120)

我使用的是@azure/storage-blob版本12.14.0,当我在本地系统上使用最新的Azure Storage Emulator 5.10调用此代码时,我得到了以下错误:
RestError:此版本的Storage Emulator不支持此请求的REST版本。请将存储模拟器升级到最新版本。有关详细信息,请参阅以下URL:http://go.microsoft.com/fwlink/?LinkId=392237

const containerClient = blobService.getContainerClient(container);
const blobClient = containerClient.getBlobClient(name);
const download = await blobClient.download();

是否有更高版本的存储模拟器可以与azure blobClient一起工作?

jq6vz3qz

jq6vz3qz1#

我下载了存储模拟器,并在存储模拟器容器中上传了一个blob,后来用Nodejs @azure/storage-blob包成功下载了它,请参阅下面:-

我的存储浏览器:-

参考:-Link1

现在,我使用下面的代码下载了带有@azure/storage-blob包的blob,并通过引用来自此MS文档的代码。

验证码:-

const { BlobServiceClient } = require("@azure/storage-blob");

// Connection string for the Azure Blob Storage emulator
const connectionString = "AccountName=xxxstoreaccount1;AccountKey=xxxxxxxxxxxxxxxxxxxtq/K1SZFPTOtr/xxxxxGMGw==;DefaultEndpointsProtocol=http;BlobEndpoint=http://xxx.0.0.1:xx000/devstoreaccount1;QueueEndpoint=http://xxx.0.0.1:xx001/devstoreaccount1;TableEndpoint=http://xxx.0.0.1:xx002/devstoreaccount1;";

// Name of the container where the blob is stored
const containerName = "test";

// Name of the blob to download
const blobName = "blob2.txt";

async function downloadBlob() {
  // Create a BlobServiceClient object using the connection string
  const blobServiceClient = BlobServiceClient.fromConnectionString(connectionString);

  // Get a reference to the container
  const containerClient = blobServiceClient.getContainerClient(containerName);

  // Get a reference to the blob
  const blobClient = containerClient.getBlobClient(blobName);

  // Download the blob to a buffer
  const downloadResponse = await blobClient.download();
  const buffer = await streamToBuffer(downloadResponse.readableStreamBody);

  // Convert the buffer to a string
  const content = buffer.toString();

  console.log(`Downloaded blob content: ${content}`);
}

async function streamToBuffer(readableStream) {
  return new Promise((resolve, reject) => {
    const chunks = [];
    readableStream.on("data", (data) => {
      chunks.push(data instanceof Buffer ? data : Buffer.from(data));
    });
    readableStream.on("end", () => {
      resolve(Buffer.concat(chunks));
    });
    readableStream.on("error", reject);
  });
}

downloadBlob();

输出:-

Blob内容下载成功:-

您可以从存储资源管理器中获取存储模拟器存储帐户的连接字符串,参考以下内容:

确保再次重新安装@azure/storage-blob包,并再次尝试运行代码以解决错误。
您可以通过在终端中运行以下命令来安装@azure/storage-blob版本12.14.0:-

npm install @azure/storage-blob@12.14.0

我的@azure/storage-blob包:-
*命令-

npm list @azure/storage-blob

我的包裹.json:-

{

"name": "pythonformrecognizer",

"version": "1.0.0",

"description": "",

"main": "storage.js",

"scripts": {

"test": "echo \"Error: no test specified\" && exit 1"

},

"keywords": [],

"author": "",

"license": "ISC",

"dependencies": {

"@azure/storage-blob": "^12.14.0"

}

}

My package-lock.json:-

"node_modules/@azure/storage-blob": {

"version": "12.14.0",

"resolved": "https://registry.npmjs.org/@azure/storage-blob/-/storage-blob-12.14.0.tgz",

"integrity": "sha512-xxxxxxF+cAMcyGLPD1P89g2M7wbEtUJWoikryxxxxx",

"dependencies": {

"@azure/abort-controller": "^1.0.0",

"@azure/core-http": "^3.0.0",

"@azure/core-lro": "^2.2.0",

"@azure/core-paging": "^1.1.1",

"@azure/core-tracing": "1.0.0-preview.13",

"@azure/logger": "^1.0.0",

"events": "^3.0.0",

"tslib": "^2.2.0"

},

"engines": {

"node": ">=14.0.0"

}

My Storage Explorer版本号:-
参考:-Storage explorer download link

Version 1.29.1

我的存储模拟器版本:-
参考:-Storage emulator download link

Windows Azure Storage Emulator v5.10.0.0

相关问题