C# Azure函数将不会创建blob元数据
我喜欢将一些元数据写入现有blob。函数运行时没有任何错误,但blob元数据未更改或未创建C# Azure函数将不会创建blob元数据,c#,azure-functions,azure-storage-blobs,C#,Azure Functions,Azure Storage Blobs,我喜欢将一些元数据写入现有blob。函数运行时没有任何错误,但blob元数据未更改或未创建 #r "Microsoft.WindowsAzure.Storage" using System; using System.Configuration; using System.Net; using System.Text; using Microsoft.Azure; using Microsoft.WindowsAzure.Storage; using Microsoft.Window
#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}");
}
输入:测试:测试:测试
输出:已处理的C#队列触发函数:teams.xlsx
这些函数在blob teams.xlsx上运行,但不创建值为“Test”的元数据“Test”
问候
Stefan感谢Crowcoder的帮助。我更改了代码,现在它运行了
wait blob.SetMetadataAsync()
我不熟悉这个操作,但是假设SetMetadataAsync()
确实是async
,您正在执行一个fire-and-forget调用,因为您不等待它。可能是请求在操作完成之前结束,导致了您的问题。这是一种可怕的做法,但只有在您能够正确实现之前才能看到发生了什么,如果您将其更改为blob.SetMetadataAsync().Result谢谢,但是。结果是行不通的。我将重建代码,以便使用wait。当我将代码粘贴到控制台应用程序中时,将得到相同的结果。