Blob metadata is not saved, although I call CloudBlob.SetMetadata

For several hours, I have been trying to set some metadata in the blob that I create using the Azure SDK. I load data asynchronously using BeginUploadFromStream() and everything works smoothly. I can access the blob using its URI when the download is complete, so it was created successfully, however, any metadata that I set is not saved .

I set the metadata after by calling EndUploadFromStream() .

I tried setting metadata in three ways that I can find in the documentation :

 // First attempt myBlob.Metadata["foo"] = "bar"; // Second attempt myBlob.Metadata.Add("foo", "bar"); //Third attempt var metadata = new NameValueCollection(); metadata["foo"] = "bar"; blob.Metadata.Add(metadata); 

After setting the metadata, I call myBlob.SetMetadata() to save the metadata in Azure, as indicated in the documentation, but it is not inserted. The call does not raise any exceptions , but when I get a new link to my blob, it has no metadata .

I also tried to save metadata asynchronously using BeginSetMetadata() and EndSetMetadata() , but with a similar result.

I'm starting to think that I am missing something really trivial here, but looking at it for five hours, I still can’t understand where I am going wrong?

+8
c # azure azure-storage-blobs
source share
1 answer

SetMetadata should work as expected. But just getting a link to blob is not enough to read metadata.

After getting the blob link, you need to call the FetchAttributes method on this CloudBlob. This will load all properties and metadata, and only then can you access the previously specified metadata:

 // Get a reference to a blob. CloudBlob blob = blobClient.GetBlobReference("mycontainer/myblob.txt"); // Populate the blob attributes. blob.FetchAttributes(); // Enumerate the blob metadata. foreach (var metadataKey in blob.Metadata.Keys) { Console.WriteLine("Metadata name: " + metadataKey.ToString()); Console.WriteLine("Metadata value: " + blob.Metadata.Get(metadataKey.ToString())); } 
+20
source share

All Articles