编程语言
首页 > 编程语言> > c# – 如何获取具有子目录级别(n级)的Blob容器中的所有blob?

c# – 如何获取具有子目录级别(n级)的Blob容器中的所有blob?

作者:互联网

尝试使用ListBlobsSegmentedAsync方法,
但这只返回主父目录级别的blob ..

但我需要从所有n级子目录中一次性获取整个blob列表.

BlobContinuationToken continuationToken = null;
bool useFlatBlobListing = true;
BlobListingDetails blobListingDetails = BlobListingDetails.None;
int maxBlobsPerRequest = 500;
var blobOptions = new BlobRequestOptions (true );

do
 {
    var listingResult = await cbDir.ListBlobsSegmentedAsync(useFlatBlobListing, blobListingDetails, maxBlobsPerRequest, continuationToken, null, null);
    continuationToken = listingResult.ContinuationToken;
    srcBlobList.AddRange(listingResult.Results);
 } while (continuationToken != null);

解决方法:

使用ListBlobsSegmentedAsync方法的重写:https://msdn.microsoft.com/en-us/library/dn434672.aspx并确保为useFlatBlobListing参数传递true.这将列出所有子目录中的所有blob.

UPDATE

这是我使用的代码,它返回该子文件夹中的blob以及该子文件夹中的所有子文件夹.

    /// <summary>
    /// Code to fetch blobs from "temp" folder inside "blah" blob container.
    /// </summary>
    private static void GetFilesInSubfolder()
    {
        var account = new CloudStorageAccount(new StorageCredentials(accountName, accountKey), true);
        var blobClient = account.CreateCloudBlobClient();
        var container = blobClient.GetContainerReference("blah");
        var directory = container.GetDirectoryReference("temp");
        var result = directory.ListBlobsSegmented(true, BlobListingDetails.None, 500, null, null, null);
        var blobs = result.Results;
    }

标签:c,azure,blobs
来源: https://codeday.me/bug/20190612/1222622.html