[英]How to get metadata of a blob from Event Grid Trigger in Azure Function
My requirement is to get metadata from the blob on an EventGridTrigger.我的要求是从 EventGridTrigger 上的 blob 获取元数据。 The ask seems to be simple, however I am not able to find examples online.
这个问题看起来很简单,但是我无法在网上找到示例。 Below is my Azure Funtion.
下面是我的 Azure 函数。 I need to get the Metadata of the blob.
我需要获取 blob 的元数据。 What is the best way of getting it.
获得它的最佳方法是什么。
public static void Run([EventGridTrigger] EventGridEvent eventGridEvent,
[Blob("{data.url}", FileAccess.Read, Connection = "AzureWebJobsStorage")] Stream input,
ExecutionContext context,
ILogger log)
{
// other lines of code
IDictionary<string, string> metadata = get_metadata_of_the_blob;
// other lines of code
}
I need to somehow get the Metadata within the function code at: get_metadata_of_the_blob我需要以某种方式获取 function 代码中的元数据: get_metadata_of_the_blob
try the following:尝试以下操作:
public static async Task Run(JObject eventGridEvent, CloudBlockBlob blob, ILogger log)
{
// ...
await blob.FetchAttributesAsync();
log.LogInformation($"\nMetadata: {string.Join(" | ", blob.Metadata.Select(i => $"{i.Key}={i.Value}"))}");
// ...
}
and the function.json:和 function.json:
{
"bindings": [
{
"type": "eventGridTrigger",
"name": "eventGridEvent",
"direction": "in"
},
{
"type": "blob",
"name": "blob",
"path": "{data.url}",
"connection": "AzureWebJobsStorage",
"direction": "in"
}
],
"disabled": false
}
First you need a blog instance then you can get the blog meta data.首先你需要一个博客实例然后你可以得到博客元数据。
try
{
BlobClient blob = new ....
// Get the blob's properties and metadata.
BlobProperties properties = await blob.GetPropertiesAsync();
Console.WriteLine("Blob metadata:");
// Enumerate the blob's metadata.
foreach (var metadataItem in properties.Metadata)
{
Console.WriteLine($"\tKey: {metadataItem.Key}");
Console.WriteLine($"\tValue: {metadataItem.Value}");
}
}
catch (RequestFailedException e)
{
Console.WriteLine(e.Message);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.