Reputation: 5162
I can't seem to find a method to access individual blob metadata for blobs in Azure Storage.
FetchAttributes only works on the whole container. My method returns a list of blobs which match the parameters I set. I then need to iterate through that list and retrieve some metadata from each of those blobs but I am not finding any methods to do so.
It seems like a lot of overhead, but should I be Fetching those attributes when I create the container object, and then filtering for the blob list?
So, I figured I'd try that,
public static IEnumerable<GalleryPhoto> GetGalleryPhotos(string folderPath)
{
var container = CreateAzureContainer(containerName, false);
container.FetchAttributes();
var blobDirectory = container.GetDirectoryReference(folderPath);
var photoGalleries = new List<GalleryPhoto>();
var blobs = blobDirectory.ListBlobs().ToList();
...rest of code
}
The blob objects in blobs, show 0 for the metadata count. Each of the items HAVE metadata, verified by looking at the properties in Azure Storage Explorer for each blob.
Any help appreciated.
Upvotes: 9
Views: 10570
Reputation: 136369
It is entirely possible to fetch the metadata in result when listing blobs. What you would need to do is specify BlobListingDetails
parameter in ListBlobs
method call and specify BlobListingDetails.Metadata
there. What this will do is include metadata for each blob in the response. So your code would be:
public static IEnumerable<GalleryPhoto> GetGalleryPhotos(string folderPath)
{
var container = CreateAzureContainer(containerName, false);
container.FetchAttributes();
var blobDirectory = container.GetDirectoryReference(folderPath);
var photoGalleries = new List<GalleryPhoto>();
var blobs = blobDirectory.ListBlobs(false, BlobListingDetails.Metadata).ToList();
...rest of code
}
Do give this a try. It should work.
Upvotes: 13
Reputation: 894
var blobs = container.ListBlobs().OfType<CloudBlockBlob>().ToList();
foreach (var blob in blobs)
{
blob.FetchAttributes(); //Now the metadata will be populated
}
Upvotes: 5