gpt4 book ai didi

azure - 如何使用 Azure JavaScript SDK 访问 blob 元数据?

转载 作者:行者123 更新时间:2023-12-03 00:38:39 26 4
gpt4 key购买 nike

如何通过 JavaScript SDK 读取 azure 中 blob 的元数据?

当我迭代从指定容器返回的 blob 时,我看到一个元数据属性:

enter image description here

但它是未定义的,即使肯定存在与 blob 关联的元数据:

enter image description here

我还需要做些什么才能填充元数据吗?

import { BlobServiceClient, SharedKeyCredential } from "@azure/storage-blob";

const account = "<redacted>";
const accountKey = "<redacted>";
const sharedKeyCredential = new SharedKeyCredential(account, accountKey);
const blobServiceClient = new BlobServiceClient(`https://${account}.blob.core.windows.net`, sharedKeyCredential);
const containerClient = blobServiceClient.getContainerClient(podcastName);

const blobs = await containerClient.listBlobsFlat({ include: ["metadata"] });
for await (const blob of blobs) {
console.log(blob.name);
//blob.metadata is undefined
}
<小时/>
// package.json relevant dependencies
"dependencies": {
"@azure/storage-blob": "^12.0.0-preview.2
}

最佳答案

// You can try this: 
for await (const blob of containerClient.listBlobsFlat()) {
const blockBlobClient = containerClient.getBlockBlobClient(blob.name);
const meta = (await blockBlobClient.getProperties()).metadata;
console.log(meta);
// process metadata
}
  • 我假设您已经声明了 blockBlobClientcontainerClient
  • 如果您还没有声明 blockBlobClientcontainerClient ,那么您可以引用 here

关于azure - 如何使用 Azure JavaScript SDK 访问 blob 元数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57765788/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com