This link mentions about storing and retrieving metadata at container level. I was just wondering if its possible to set and retrieve metadata about a blob stored in a directory inside that container?
1 Answer
I was just wondering if its possible to set and retrieve metadata about a blob stored in a directory inside that container?
Yes, you can certainly do so. Please see the sample code below:
const string ConnectionString = "DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key";
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(ConnectionString);
//Create the service client object for credentialed access to the Blob service.
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
// Retrieve a reference to a container.
CloudBlobContainer container = blobClient.GetContainerReference("mycontainer");
CloudBlockBlob blob = container.GetBlockBlobReference("images/logo.png");
blob.FetchAttributes();//Gets the properties & metadata for the blob.
blob.Metadata.Add("Key", "Value");
blob.SetMetadata();//Saves the metadata.
2 Comments
blue piranha
Thanks! I am glad I checked this post again coz I was disheartened when you initially said that it was not possible.
Gaurav Mantri
Sorry....my bad! I read the post incorrectly. I thought you wanted to set metadata on the folder. Once I reread the question, I realized my mistake and edited my answer. Sorry about that!