2

In our Azure portal I have created a storage account and inside created a blob container and inside that a blob which is just a simple text file. I have also set the some random metadata fields on the blob seen here. enter image description here

In my java code when I access the blob via the Azure SDK I can print the content of the blob, I can acccess the blob properties like the Etag and I can access the container metadata. But I cannot print the blob metadata fields seen above. Specifically this code taken from the samples page doesn't print anything since the received HashMap from blob.getMetadata() method is empty.

System.out.println("Get blob metadata:"); 
             HashMap<String, String> metadata = blob.getMetadata(); 
             Iterator it = metadata.entrySet().iterator(); 
             while (it.hasNext()) { 
                Map.Entry pair = (Map.Entry) it.next(); 
                 System.out.printf(" %s = %s%n", pair.getKey(), pair.getValue()); 
                 it.remove(); 
             } 

If I instead make a REST API call to the blob and ask for the metadata fields I do get them back as HTTP headers. However I would like to access them via the SDK if possible.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61
Souciance Eqdam Rashti
  • 3,143
  • 3
  • 15
  • 31

1 Answers1

2

Before blob.getMetadata(), use blob.downloadAttributes()

This method populates the blob's system properties and user-defined metadata. Before reading or modifying a blob's properties or metadata, call this method or its overload to retrieve the latest values for the blob's properties and metadata from the Microsoft Azure storage service.

Jerry Liu
  • 17,282
  • 4
  • 40
  • 61