2

With Microsoft.WindowsAzure.Storage.Blob one could enumerate a large BLOB container using the BlobContinuationToken in the ListBlobsSegmentedAsync method, and the BlobResultSegment would include the ContinuationToken property if a subsequent read would be required to retrieve more from the container.

With Azure.Storage.Blobs it appears the enumeration API is BlobContainerClient.GetBlobsAsync but the method signature does not provide a means of supplying a continuation token, and the results as Azure.AsyncPageable<BlobItem> do not appear to provide a property that is a continuation token.

Does anyone have a code snippet for enumerating large BLOB containers on Azure, using continuation tokens, via the Azure.Storage.Blobs package?

1 Answer 1

3

If you really want to use a continuation token you can do so:

    string continuationToken = null;
    var container = new BlobContainerClient("xxx", "test");
    var blobPages = container.GetBlobsAsync().AsPages();
        
    await foreach (var page in blobPages)
    {
        continuationToken = page.ContinuationToken;
        foreach(var blob in page.Values)
        {
            ...
        }
    }

You can pass the token to AsPages to continue iteration:

blobPages = container.GetBlobsAsync().AsPages(continuationToken: continuationToken);

or you can just iterate over the blobs, let the SDK do the job of providing all the data using a stream of blobs:

    var container = new BlobContainerClient("xxx", "test");
    var blobs = container.GetBlobsAsync();
        
    await foreach (var blob in blobs)
    {
        //
    }

Iterating over the blobs can make multiple calls to the blob service.

For more about pagination in the SDK see the docs.

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, exactly what I needed. Yes, I agree the best approach would be to allow the SDK to do its job, but in this case, the implementation expects a continuation token. Thanks for putting this answer together Peter!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.