locked
Can't retrieve metadata from azure blobs RRS feed

  • Question

  • Hello,

    I am trying to retrieve metadata from a blob but the metadata property is null.  In the azure portal, I can see that the metadata that I set is present in the blob.  Also I know that the right blob is being retrieved because while debugging I can see that the name property of the blob is correct.  I am using the v12 sdk for blob storage.  The method that I am calling is below.

    public Patient[] SearchRelationships(string doctorID)
            {
                if (BlobServiceClient.GetBlobContainerClient("doctor-" + doctorID).Exists())
                {
                    Azure.Pageable<BlobItem> blobs = BlobServiceClient.GetBlobContainerClient("doctor-" + doctorID).GetBlobs();
                    List<Patient> patients = new List<Patient>();
                    foreach (BlobItem blob in blobs)
                    {
                        patients.Add(new Patient(blob.Metadata["radiologist"]));
                    }

                    return patients.ToArray();
                }

                return null;
            }

    Wednesday, January 22, 2020 8:47 PM

All replies

  • May I know what exactly happens when you try to retrieve the meta data are you getting any error code or message, If so, can you share me the screenshot?

    Just for clarification are trying to retrieve individual blob meta data?

    This SO thread  Setting and Retrieving metadata of blob in Azure Blob Storage   provides an idea how you can perform this  query.

    Additional information: Manage container properties and metadata with .NET

    Retrieve Azure blob metadata via PS

    Kindly let us know if the above helps or you need further assistance on this issue. 
    ------------------------------------------------------------------------------------------

    Do click on "Mark as Answer" and Upvote on the post that helps you, this can be beneficial to other community members.

    Thursday, January 23, 2020 3:56 AM
  • @CharlieK37 Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Monday, January 27, 2020 10:21 AM
  • You need to use BlobClientBase class and call GetProperties method on it. It will return BlobProperties which contains the field metadata.

    Don't forget to include the namespaces.

    using Azure.Storage.Blobs.Models;
    using Azure.Storage.Blobs.Specialized;

    public Patient[] SearchRelationships(string doctorID)
    {


        var containerClient = BlobServiceClient.GetBlobContainerClient("doctor-" + doctorID);
        if (containerClient.Exists())
        {
            Azure.Pageable<BlobItem> blobs = BlobServiceClient.GetBlobContainerClient("doctor-" + doctorID).GetBlobs();
            List<Patient> patients = new List<Patient>();
            foreach (BlobItem blob in blobs)
            {
                var blobBaseClient = containerClient.GetBlobBaseClient(blob.Name);
                var blobProperties = blobBaseClient.GetProperties();

                if(blobProperties.Metadata.Count > 0)
                    {
                        patients.Add(new Patient(blobProperties.Metadata["radiologist"]));
                    }
            }

            return patients.ToArray();
        }

        return null;
    }




    Friday, January 31, 2020 10:50 AM
  • Just checking in to see if the above answer helped. If this answers your query, do click “Mark as Answer” and Up-Vote for the same, which might be beneficial to other community members reading this thread. And, if you have any further query do let us know.
    Thursday, February 6, 2020 3:41 AM