如何从 Azure 函数输出多个 blob?

How to output multiple blobs from an Azure Function?

Out 绑定有示例:

ICollector<T> (to output multiple blobs)

还有:

Path must contain the container name and the blob name to write to. For example,
if you have a queue trigger in your function, you can use "path":
"samples-workitems/{queueTrigger}" to point to a blob in the samples-workitems
container with a name that matches the blob name specified in the trigger
message.

而 "Integrate" 中的默认值 UI 的默认值为:

Path: outcontainer/{rand-guid}

但这还不足以让我取得进展。如果我在 C# 中编码,function.json 和 run.csx 将多个 blob 输出到容器的语法是什么?

您可以通过多种不同的方式完成此操作。首先,如果您需要输出的 blob 数量是固定的,您可以只使用多个输出绑定。

using System;

public class Input
{
    public string Container { get; set; }
    public string First { get; set; }
    public string Second { get; set; }
}

public static void Run(Input input, out string first, out string second, TraceWriter log)
{
    log.Info($"Writing 2 blobs to container {input.Container}");
    first = "Azure";
    second = "Functions";
}

和对应的function.json:

{
  "bindings": [
    {
      "type": "manualTrigger",
      "direction": "in",
      "name": "input"
    },
    {
      "type": "blob",
      "name": "first",
      "path": "{Container}/{First}",
      "connection": "functionfun_STORAGE",
      "direction": "out"
    },
    {
      "type": "blob",
      "name": "second",
      "path": "{Container}/{Second}",
      "connection": "functionfun_STORAGE",
      "direction": "out"
    }
  ]
}

为了测试上面的内容,我向函数发送了一个测试 JSON 负载,然后生成了 blob:

{
  Container: "test",
  First: "test1",
  Second: "test2"
}

上面的示例演示了如何从输入中绑定 blob container/name 值(通过 {Container}/{First} {Container}/{Second} 路径表达式)。您只需定义一个 POCO 来捕获您想要绑定的值。为简单起见,我在这里使用了 ManualTrigger,但这也适用于其他触发器类型。此外,虽然我选择绑定到 out string 类型,但您可以绑定到任何其他受支持的类型:TextWriterStreamCloudBlockBlob 等。

如果你需要输出的blob数量是可变的,那么你可以使用Binder命令式的绑定写入你的blob功能代码。有关详细信息,请参阅 。要绑定到多个输出,您只需使用该技术执行多个命令式绑定。

仅供参考:我们的文档不正确,所以我记录了一个错误 here 来修复它:)