You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

@azure/storage-blob与IoT Edge Azure Blob存储模块不兼容,需设置API版本

解决Node.js Azure Storage Blob SDK与IoT Edge Blob模块API版本不兼容问题

问题核心:@azure/storage-blob SDK默认使用的Storage API版本为2022-11-02,但IoT Edge上的Blob存储模块仅兼容2017-04-17版本,导致请求时返回InvalidHeaderValue错误,提示x-ms-version值无效。

解决方案

在创建BlobServiceClient时,通过配置选项显式指定API版本:

修改后的代码示例:

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

const account = "<account>";
const defaultAzureCredential = new DefaultAzureCredential();

// 添加serviceVersion配置指定API版本
const blobServiceClient = new BlobServiceClient(
  `https://${account}.blob.core.windows.net`,
  defaultAzureCredential,
  {
    serviceVersion: "2017-04-17"
  }
);

async function main() {
  let i = 1;
  let containers = blobServiceClient.listContainers();
  for await (const container of containers) {
    console.log(`Container ${i++}: ${container.name}`);
  }
}

main();

说明

  • serviceVersion是BlobServiceClientOptions对象的可选属性,用于指定请求使用的Azure Storage API版本。
  • 设置该参数后,SDK会自动将指定的版本号填入x-ms-version请求头,匹配IoT Edge Blob模块的兼容版本要求。
  • 支持的版本值可参考SDK内部定义的枚举,确保使用目标模块兼容的版本字符串。

内容的提问来源于stack exchange,提问作者crafman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.24 21:37:39