List blob versions

JT One Admin 1 Reputation point
2021-02-01T18:32:22.077+00:00

Is there a way to list all of a specific blob's versions without having to list all the blobs and all their versions within a container?

If I have a pointer to a blob, can I get a list of that blob's versions?

Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,639 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. deherman-MSFT 35,636 Reputation points Microsoft Employee
    2021-02-01T22:17:57.9+00:00

    @JT One Admin
    If you are using the .net SDK please see if this code might work for your use case:

    public static class BlobContainerClientExtensions  
        {  
            public static async IAsyncEnumerable<string?> GetVersions(this BlobContainerClient blobContainerClient, string blobName)  
            {  
                var resultSegment = blobContainerClient.GetBlobsAsync(BlobTraits.None, BlobStates.Version, prefix: blobName).AsPages(default, 100);  
                await foreach (var blobPage in resultSegment)  
                    foreach (var blobItem in blobPage.Values)  
                        yield return blobItem.VersionId;  
            }  
        }  
    

    The easiest way to view the versions of an individual blob would be to use Storage Explorer. To view a blob's versions, select the blob you want to view versions for and select Manage History → Manage Versions from either the toolbar or the context menu.

    Hope this helps. Let us know if you have further questions or issues.

    -------------------------------

    Please don’t forget to "Accept the answer" and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    0 comments No comments