如何在 CloudBlobContainer.ListBlobs() 中使用前缀参数从 Azure blob 存储中的虚



我正在尝试在 Azure blob 存储中的单个虚拟文件夹中获取列表。这些文件按/{容器}/{分类}/{标题} 文件夹结构进行组织,所有文件都位于"title"虚拟文件夹中。

这是我使用的函数,它没有前缀,但在提供前缀时无法返回任何结果。

public static List<string> List(string classification, string title, StorageAccount sa)
{
    List<string> fileList = new List<string>();
    CloudBlobContainer container = GetBlobContainer(sa);
    var prefix = $"/{container.Name}/{classification}/{title}/";
    Console.WriteLine(prefix);
    var list = container.ListBlobs(prefix, useFlatBlobListing: true);
    foreach (var blob in list)
    {
        var blobFileName = blob.Uri.AbsolutePath;
        fileList.Add(blobFileName);
    }
    return fileList;
}

无需在前缀中包含容器名称。请更改以下代码行:

var prefix = $"/{container.Name}/{classification}/{title}/";

自:

var prefix = $"{classification}/{title}/";

这将列出以该前缀开头的所有 blob 名称。

最新更新