You are developing a C# application using the Azure.Storage.Blobs SDK (v12). You need to add a new custom metadata tag to an existing blob while preserving all existing metadata on that blob. How should you order the steps to perform this update?
- 1Call GetPropertiesAsync() on the BlobClient instance to retrieve the blob's current properties.
- 2Retrieve the Metadata dictionary from the returned properties object.
- 3Add or modify the key-value pairs in the dictionary, ensuring keys do not include the x-ms-meta- prefix.
- 4Invoke SetMetadataAsync() on the BlobClient with the modified dictionary as the argument.
Answer
To update the custom metadata on an existing blob while preserving its current metadata, you must first call GetPropertiesAsync() on the BlobClient, extract the Metadata dictionary, update the dictionary with the new key-value pairs (omitting the x-ms-meta- prefix), and finally call SetMetadataAsync() with the updated dictionary.
To preserve existing metadata, the application must read the existing metadata first. This is done by calling GetPropertiesAsync() and accessing the Metadata dictionary. After modifying or adding entries to this dictionary (without adding the 'x-ms-meta-' prefix), the dictionary is passed to SetMetadataAsync() to update the blob.
Step-by-Step Solution
Key Concept
Read-modify-write pattern for Azure Blob metadata operations