You need to update a specific metadata tag on an existing Azure Blob Storage blob using the Azure.Storage.Blobs SDK (v12) for C# while ensuring that all other existing metadata key-value pairs on the blob are preserved. Which sequence of steps should you perform?
- 1Instantiate a BlobClient referencing the target blob using an authorized connection string.
- 2Call GetPropertiesAsync() on the client and access the Metadata dictionary from the returned properties.
- 3Add or modify the target key-value pairs directly within the retrieved metadata dictionary without prefixing keys with x-ms-meta-.
- 4Call SetMetadataAsync() on the client, passing the updated metadata dictionary as the argument.
Answer
To update a specific metadata key on a blob while preserving existing metadata using the Azure.Storage.Blobs SDK (v12) for C#, you must first instantiate a BlobClient, call GetPropertiesAsync() to retrieve the current Metadata dictionary, modify or add the key-value pairs in memory, and then call SetMetadataAsync() with the updated dictionary.
The correct order requires first initializing the BlobClient to communicate with the service, then calling GetPropertiesAsync() to fetch the existing metadata so it is not lost. Next, the metadata dictionary is modified in memory, and finally, SetMetadataAsync() is called to upload the entire updated dictionary.
Step-by-Step Solution
Key Concept
Preserving metadata during updates with Azure.Storage.Blobs SDK