简体   繁体   中英

Adding Tag to Azure Blob C#

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);

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM