Reputation: 585
I like to write some metadata to an existing blob. The function runs without any error but the blob metadata not changes or not created.
#r "Microsoft.WindowsAzure.Storage"
using System; using System.Configuration; using System.Net; using
System.Text; using Microsoft.Azure; using
Microsoft.WindowsAzure.Storage; using
Microsoft.WindowsAzure.Storage.Blob;
public static void Run(string myQueueItem, ILogger log) {
string[] myQueueItems = myQueueItem.Split(':');
string DocumentID = myQueueItems[0];
string MetaDataKey = myQueueItems[1];
string MetaDataValue = myQueueItems[2];
CloudStorageAccount storageAccount = CloudStorageAccount.Parse("");
CloudBlobClient blobClient = storageAccount.CreateCloudBlobClient();
CloudBlobContainer container = blobClient.GetContainerReference("test123");
CloudBlob blob = container.GetBlobReference("teams.xlsx");
blob.FetchAttributesAsync();
if (blob.Metadata.ContainsKey(MetaDataKey))
{
blob.Metadata[MetaDataKey] = MetaDataValue;
}
else{
blob.Metadata.Add(MetaDataKey, MetaDataValue);
}
blob.SetMetadataAsync();
log.LogInformation($"C# Queue trigger function processed: {blob.Name}");
}
Input: Test:Test:Test Output: C# Queue trigger function processed:teams.xlsx
The functions runs but not create the metadata “Test” with the value “Test” on the blob teams.xlsx.
Regards Stefan
Upvotes: 1
Views: 583
Reputation: 585
Thank you Crowcoder for your help. I Change the code and now it runs.
await blob.SetMetadataAsync();
Upvotes: 1