1

Assembly in use: Assembly Microsoft.WindowsAzure.Storage, Version=9.3.1.0

What I want to do: In my Azure storage, I have images stored as a blob, in the following fashion

enter image description here

I want to get the URLs of all the image blobs along with their last modified timestamp.

Please note that Image1 and Image4 might have the same name.

What I have tried:

  1. I tried ListBlobsSegmentedAsync(BlobContinuationToken currentToken) from the root of the container and by using GetDirectoryReference(string relativeAddress) but couldn't get the desired result.

  2. Though a bit off track, I am able to get the blob details by GetBlockBlobReference(string blobName);

What should I do?

Thanks in advance.

1
  • Well, remember that blob storage does not actually have folders, they are virtual. So you really have blobs with names e.g. "Folder1/Image1.png". ListBlobsSegemented should give you all the blobs, can you show the code you tried? Commented Feb 11, 2020 at 12:45

2 Answers 2

1

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.

Use the following code to list all blob in container.

public static async Task test()
{
    StorageCredentials storageCredentials = new StorageCredentials("xxx", "xxxxx");
    CloudStorageAccount storageAccount = new CloudStorageAccount(storageCredentials, true);
    CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
    CloudBlobContainer container = blobClient.GetContainerReference("container");
    BlobContinuationToken blobContinuationToken = null;
    var resultSegment = await container.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);
     }
}

The result is as below:

enter image description here

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

1 Comment

Thanks, by mistake I was using 'ListBlobsSegmentedAsync' of 'CloudBlobClient'.
0

Please try this override of ListBlobsSegmentedAsync with the following parameters:

prefix: ""

useFlatBlobListing: true

blobListingDetails: BlobListingDetails.All

maxResults: 5000

currentToken: null or the continuation token returned

This will return you a list of all blobs (including inside virtual folders)

Comments

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.