Home > Mobile >  Remove Metadata from Blob using Azure.Storage (v12 SDK)
Remove Metadata from Blob using Azure.Storage (v12 SDK)

Time:10-04

I've created a method that adds metadata to an Azure Blob. I also need to remove metadata and can't find any specific method or documentation to help me.

Is the only way to create a brand new set of metadata and overwrite it using SetMetadata() or is there a better way?

CodePudding user response:

The only way to "remove" (reset) metadata is, like you said, to create a new set of metadata & overwrite existing metadata using SetMetaData or SetMetaDataAsync.

Currently, as of .NET v12 SDK, there is no way to reset metadata.

Something like this should work:

public static async Task ResetBlobMetadataAsync(BlobContainerClient container)
{
    try
    {
        var newMetadata = new Dictionary<string, string>();
        await container.SetMetadataAsync(metadata);
    }
    catch (RequestFailedException e)
    {
        Console.WriteLine($"HTTP error code {e.Status}: {e.ErrorCode}");
        Console.WriteLine(e.Message);
        Console.ReadLine();
    }
}
  • Related