【问题标题】:Azure Blob Storage get file list from specific directory not from containerAzure Blob 存储从特定目录而不是容器获取文件列表
【发布时间】:2021-10-10 12:10:21
【问题描述】:

我已经创建了从 Azure blob 容器中获取文件列表的代码。

const sharedKeyCredential = new StorageSharedKeyCredential(account, accountKey);

 const containerName = `newcontainer${new Date().getTime()}`;
  const containerClient = new ContainerClient(
    `https://${account}.blob.core.windows.net/${containerName}`,
    sharedKeyCredential
  );


 console.log("Listing all blobs");
  i = 1;
  for await (const blob of containerClient.listBlobsFlat()) {
    console.log(`Blob ${i++}: ${blob.name}`);
  }

以上代码返回所有文件的列表。 但在我的容器中,有两个文件夹,一个是 IN 文件夹,第二个是 OUT 文件夹。我只需要 IN 文件夹中的文件列表。

是否有任何函数可用于从特定目录获取列表?

【问题讨论】:

    标签: node.js azure-blob-storage


    【解决方案1】:

    只需在您的listBlobsFlat 方法中添加prefix 选项,您就可以仅列出IN 文件夹中的blob。比如:

    for await (const blob of containerClient.listBlobsFlat({prefix: 'IN/'})) {
        console.log(`Blob ${i++}: ${blob.name}`);
    }
    

    您可以在此处了解有关 Blob 列表选项的更多信息:https://docs.microsoft.com/en-us/javascript/api/@azure/storage-blob/containerlistblobsoptions?view=azure-node-latest

    【讨论】:

      猜你喜欢
      • 2020-07-04
      • 2021-06-22
      • 1970-01-01
      • 2020-12-26
      • 2019-06-28
      • 1970-01-01
      • 2021-08-02
      • 2018-11-07
      • 2020-09-05
      相关资源
      最近更新 更多