如何获取具有子目录级别(n个级别)的Blob容器中的所有Blob? [英] How to get hold of all the blobs in a Blob container which has sub directories levels(n levels)?

查看:110
本文介绍了如何获取具有子目录级别(n个级别)的Blob容器中的所有Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Tried using the ListBlobsSegmentedAsync method , but this returns only the blobs from the main parent directory level ..

但是我需要从所有n个子目录级别中一次删除整个blob.

But I need the entire list of blobs at one go from all the n levels of subdirectories.

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);

推荐答案

命名参数,以使代码更易于理解.

The ListBlobsSegmentedAsync method has 2 overloads that contain the useFlatBlobListing argument. These overloads accept 7 or 8 arguments, and I count 6 in your code. Because there are so many arguments, you can use named arguments to make the code easier to understand.

以下代码已在.NET Core中成功测试.

The code below has been tested successfully in .NET Core.

BlobContinuationToken blobContinuationToken = null;
do
{
    var resultSegment = await cloudBlobContainer.ListBlobsSegmentedAsync(
        prefix            : null,
        useFlatBlobListing: true, 
        blobListingDetails: BlobListingDetails.None,
        maxResults        : null,
        currentToken      : blobContinuationToken,
        options           : null,
        operationContext  : null
    );

    // Get the value of the continuation token returned by the listing call.
    blobContinuationToken = resultSegment.ContinuationToken;
    foreach (IListBlobItem item in resultSegment.Results)
    {
        Console.WriteLine(item.Uri);
    }
} while (blobContinuationToken != null); // Loop while the continuation token is not null.

此代码源自Microsoft的 storage-blobs-dotnet-quickstart 存储库.

This code is derived from Microsoft's storage-blobs-dotnet-quickstart repository.

这篇关于如何获取具有子目录级别(n个级别)的Blob容器中的所有Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆