我正在使用Azure Blob存储来存储我的一些文件。我将它们归类在不同的文件夹中。
到目前为止,我可以使用以下命令获取容器中所有斑点的列表:
public async Task<List<Uri>> GetFullBlobsAsync()
{
var blobList = await Container.ListBlobsSegmentedAsync(string.Empty, true, BlobListingDetails.None, int.MaxValue, null, null, null);
return (from blob in blobList.Results where !blob.Uri.Segments.LastOrDefault().EndsWith("-thumb") select blob.Uri).ToList();
}
Run Code Online (Sandbox Code Playgroud)
但是,如何只获取文件夹,然后才能获取该特定子目录中的文件?
这是在ASP.NET Core上
编辑:
容器结构如下所示:
Container
|
|
____Folder 1
| ____File 1
| ____File 2
|
|
____Folder 2
____File 3
____File 4
____File 5
____File 6
Run Code Online (Sandbox Code Playgroud) 我正在使用一个 Azure Blob 存储容器,该容器内部和存放文件的位置有许多假文件夹结构。
我试图使用此代码块来获取层次结构值和 blob,以便我可以将它们返回到调用方法。
private async Task<List<BlobItem>> ListBlobsHierarchicalListing(
BlobContainerClient container,
string prefix)
{
var list = new List<BlobItem>();
var resultSegment =
await container.GetBlobsByHierarchyAsync(prefix: prefix, delimiter: "/").ToListAsync();
// A hierarchical listing may return both virtual directories and blobs.
foreach (BlobHierarchyItem blobhierarchyItem in resultSegment)
{
if (blobhierarchyItem.IsPrefix)
{
// Write out the prefix of the virtual directory.
this.logger.LogDebug("Virtual directory prefix: {0}", blobhierarchyItem.Prefix);
// Call recursively with the prefix to traverse the virtual directory.
list.AddRange(await this.ListBlobsHierarchicalListing(container, blobhierarchyItem.Prefix));
}
else
{
// …
Run Code Online (Sandbox Code Playgroud)