从触发 blob 触发 Azure 函数的文件中获取元数据

Get metadata from file that triggered blob trigger Azure function

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

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

您可以绑定到 CloudBlockBlob,而不是绑定到 Stream。然后你可以做

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

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