简体   繁体   English

如何从事件网格触发器中获取 blob 的元数据 Azure Function

[英]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.

相关问题 HTTP 触发器 azure function 从 blob 存储错误获取图像 - HTTP trigger azure function get image from blob storage error 无法使用 Azure Function Blob 触发器获取 Blob SAS URL - Unable to get Blob SAS URL using Azure Function Blob trigger 如何获取触发 Azure Function Blob 触发器的文件名 - How do I get the file name that triggered a Azure Function Blob Trigger 如何提供来自 Azure Function 和 Storage Blob 的 GET 请求? - How to serve up a GET request from Azure Function and Storage Blob? 从事件网格触发的 function 访问存储容器中的 blob - Access blob in storage container from function triggered by Event Grid Azure Function 未被触发 - Blob 存储触发器 - Azure Function is not getting triggered - Blob Storage Trigger 事件网格触发器未触发 Azure 函数 - Event Grid Trigger Not Firing For Azure Functions Azure 具有事件网格触发器扩展的功能 - Azure Functions with Event Grid Trigger Scale Up 在 Azure 数据工厂中获取 blob 文件的自定义元数据 - Get custom metadata for blob files in Azure data factory 如何将 CosmosDB 依赖项跟踪数据从 Azure Function 事件中心触发器发送到 Application Insights - How to send CosmosDB dependency tracking data to Application Insights from Azure Function Event Hub Trigger
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM