Describe the bug
The Blobs_12.4.4 GetBlobs returns null as the metadata even though the blob shows metadata in the Azure portal.
Expected behavior
The blob's Metadata property contains the key value pairs of metadata.
Actual behavior (include Exception or Stack Trace)
The blob's Metadata is null.
To Reproduce
Steps to reproduce the behavior (include a code snippet, screenshot, or any additional information that might help us reproduce the issue)
var container = new BlobContainerClient(connectionString, containerName);
var blobs = container.GetBlobs()
foreach (BlobItem blob in blobs)
{
if(blob.Metadata != null)
{
Console.WriteLine("Blob Metadata:");
foreach (var item in blob.Metadata)
{
Console.WriteLine("Key: {item.Key}, Value: {item.Value}");
}
else
{
Console.WriteLine("Blob Metadata: none");
}
}
Environment:
Thanks for the feedback! We are routing this to the appropriate team for follow-up. cc @shenmuxiaosen, @avanigupta.
Hi @richaplinvs. To include metadata when getting blobs for a container, you need to use BlobTraits.Metadata as a parameter.
```
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApp13
{
class Program
{
static readonly string ConnectionString = "";
static async Task Main(string[] args)
{
BlobServiceClient blobServiceClient = new BlobServiceClient(ConnectionString);
BlobContainerClient blobContainerClient = blobServiceClient.GetBlobContainerClient("mycontainer023142341");
try
{
await blobContainerClient.CreateAsync();
AppendBlobClient appendBlobClient = blobContainerClient.GetAppendBlobClient("myappendblob");
await appendBlobClient.CreateAsync();
Dictionary<string, string> metadata = new Dictionary<string, string>
{
{ "key", "value" }
};
await appendBlobClient.SetMetadataAsync(metadata);
await appendBlobClient.GetPropertiesAsync();
// Metadata will not be included unless you use traits: BlobTraits.Metadata.
await foreach (BlobItem blobItem in blobContainerClient.GetBlobsAsync(traits: BlobTraits.Metadata))
{
if (blobItem.Metadata != null)
{
Console.WriteLine("Blob Metadata:");
foreach (KeyValuePair<string, string> item in blobItem.Metadata)
{
Console.WriteLine($"Key: {item.Key}, Value: {item.Value}");
}
}
else
{
Console.WriteLine("Blob Metadata: none");
}
}
}
finally
{
await blobContainerClient.DeleteAsync();
}
}
}
}
Hi @seanmcc-msft, thanks for the clarification - much appreciated.
@richaplinvs, glad to help.
Most helpful comment
Hi @richaplinvs. To include metadata when getting blobs for a container, you need to use
BlobTraits.Metadataas a parameter.```
using Azure.Storage.Blobs;
using Azure.Storage.Blobs.Models;
using Azure.Storage.Blobs.Specialized;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
namespace ConsoleApp13
{
class Program
{
static readonly string ConnectionString = "";
}