【问题标题】:Get azure container blobs list by directory按目录获取 azure 容器 blob 列表
【发布时间】:2020-07-04 04:52:04
【问题描述】:

我正在按目录组织我的容器内容

rep1/subrep1/subsubrep1'
rep2/subrep2/subsubrep2'

在每个代表中我都有 blob 文件。

我想检索 `rep1/subrep1/subsubrep1' 的 blob 列表

容器名为tenants

try {
    const blobServiceClient = await BlobServiceClient.fromConnectionString(
        process.env.AzureWebJobsStorage
    );

    const containerClient = await blobServiceClient.getContainerClient(
        'tenants'
    );
    for await (const blob of containerClient.listBlobsFlat()) {
        let blobClient = await containerClient.getBlobClient(blob.name);
        let splitedString = blobClient.name.split('/')
        filesList.push({
            label: splitedString[splitedString.length].split(".wav")[0],
            value: blobClient.url
        });
    }
} catch (err) {
    console.log(err)
}

实际上,我应该使用我的代码迭代所有 blob 文件。

我可以过滤结果,但我会找到如何获取特定的子文件夹 blob

【问题讨论】:

    标签: javascript azure-storage azure-blob-storage azure-container-service


    【解决方案1】:

    不要使用listBlobsFlat,而是使用listBlobsByHierachy。对于delimiter参数,指定一个空字符串,并在options参数中指定rep1/subrep1/subsubrep1prefix

    类似:

    let iter = await containerClient.listBlobsByHierarchy("", { prefix: "rep1/subrep1/subsubrep1/" });
    

    【讨论】:

    • 当我使用这个方法The MAC signature found in the HTTP request 'btOFCQtx3dyes5TzPbpMZxxxxxxxxx' is not the same as any computed signature. Server used following string to sign: 'GET时,我得到了这个访问授权错误
    • 我的错,我犯了一个小错误。我忘记了字符串末尾的 / 并添加了 "/" 而不是 '' 作为第一个参数。现在它正在工作,谢谢。
    猜你喜欢
    • 1970-01-01
    • 2020-09-03
    • 2021-10-10
    • 2019-06-28
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 2014-06-22
    • 2015-11-10
    相关资源
    最近更新 更多