首页 > 解决方案 > 从触发 blob 触发 Azure 函数的文件中获取元数据

问题描述

我有一个 blob 触发器 Azure 函数,每次将新文件添加到我的 blob 存储时都会调用该函数。我自动获取该文件的名称作为输入。除了名称之外,我还需要附加到给定文件的元数据。我一直在研究数据输入绑定,但我无法理解。我需要做什么才能将文件元数据作为输入?或者,甚至只是在我的函数中访问它?

public static void Run(Stream myBlob, string name, TraceWriter log)
{
    string result = DoSomethingWithFileName(name);
    var something = DoSomethingWithFileMetadata();
}

标签: azuredata-bindingazure-blob-storageazure-functionsazure-triggers

解决方案


而不是绑定到 aStream你可以绑定到 a CloudBlockBlob。然后你可以做

public static Task Run(CloudBlockBlob myBlob, string name, TraceWriter log)
{
    string result = DoSomethingWithFileName(myBlob.Name);
    var something = DoSomethingWithFileMetadata(myBlob.Metadata);
}

如果您需要流,则可以调用.OpenRead().OpenReadAsync()


推荐阅读