Home > Back-end >  List Blobs in Azure Storage Container including Metadata
List Blobs in Azure Storage Container including Metadata

Time:11-28

I am creating list of Blobs in a container and iterating through them. However every single Blob's Metadata dictionary remains empty. I understand I need to populate / fetch them.

There is BlobContainerClient.GetProperties method which gets metadata, but no blobs itself.

How can I get list of Blobs with its Metadata populated so can iterate through Blobs, get its name, properties but also Metadata by a Key?

{
    string BlobPrefix = "prefix";
    BlobContainerClient containerClient = new BlobContainerClient("connectionstring", "docrepo");
    var blobList = containerClient.GetBlobs(prefix: BlobPrefix);

    foreach (var blob in blobList)
    {
        Console.Writeline(blob.Name);
        Console.Writeline(blob.Properties.CreatedOn.Value.UtcDateTime);
        Console.Writeline(blob.Metadata.Item("KeyName"));
    }
}

Using .NET v12 SDK.

CodePudding user response:

You may pass traits parameter as BlobTraits.Metadata this means the blob's metadata should be included.

Example

var blobList = containerClient.GetBlobs(BlobTraits.Metadata, BlobStates.All, BlobPrefix);
  • Related