Adding Tag to Azure Blob C#

Viewed 72

I currently use this to upload a Blob to Azure and it works fine, but I'd like to add tag(s) to the file before uploading it. How do I go about adding tags to the file?

    var blobClient = storageAccount.CreateCloudBlobClient();
    var container = blobClient.GetContainerReference(craftId.ToString());
    var blob = container.GetBlockBlobReference(newFileName);
    blob.Properties.ContentType = image.ImageType;


    await blob.UploadFromByteArrayAsync(image.Image, 0, image.Image.Length);
1 Answers

I'm not sure whether you mean actual Tags or just Metadata. Anyway, this shows both:

uses Azure.Storage.Blobs v12.13.1

BlockBlobClient blob;
//...

await blob.UploadAsync(yourContentAsAStream);
var metaData = new Dictionary<string, string>
{
    { "testmetadata", "hello world" }
};
await blob.SetMetadataAsync(metaData);

var tags = new Dictionary<string, string>
{
    { "testtag", "mytag" }
};
await blob.SetTagsAsync(tags);
Related