How to get hold of all the blobs in a Blob container which has sub directories levels(n levels)?

前端 未结 2 1570
梦如初夏
梦如初夏 2020-12-03 18:00

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

But I need the entire list of blobs at one

2条回答
  •  情深已故
    2020-12-03 18:58

    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.

    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.
    

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

提交回复
热议问题