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

Azure functions 如何从Azure函数输出多个blob?,azure-functions,Azure Functions,Out绑定有以下示例: ICollector<T> (to output multiple blobs) “集成”UI中的默认值为: Path: outcontainer/{rand-guid} 但这还不足以让我取得进展。如果我用C#编码,function.json和run.csx的语法是什么,以将多个blob输出到一个容器 有几种不同的方法可以实现这一点。首先,如果需要输出的blob数量是固定的,则可以使用多个输出绑定 using System; public class I

Out绑定有以下示例:

ICollector<T> (to output multiple blobs)
“集成”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}/{First}
{container}/{Second}
路径表达式)。您只需定义一个POCO来捕获要绑定到的值。为了简单起见,我在这里使用ManualTrigger,但这也适用于其他触发器类型。此外,当我选择绑定到
out string
类型时,您可以绑定到任何其他受支持的类型:
TextWriter
Stream
CloudBlockBlob
,等等

如果需要输出的BLOB数为变量,则可以使用绑定器强制绑定并在函数代码中写入BLOB。有关更多详细信息,请参阅。要绑定到多个输出,只需使用该技术执行多个命令绑定


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

我正在尝试命令式模式。我收到一个编译错误-请参见下面的//命令绑定到存储blobPath=$“json/{fileNamePart}{dateString}”;var attributes=new Attribute[]{new blobatAttribute(blobPath),new StorageAccountAttribute(storageAccount)};使用(var writer=binder.Bind(attributes)){writer.Write(jsonString.ToString();}错误:2017-02-12T00:43:43.243函数启动(Id=6d48c79d-5af3-4c9a-b4ab-242d186e7c33)2017-02-12T00:43:43.243函数编译错误2017-02-12T00:43:43.243(225,73):错误CS1026:)预计2017-02-12T00:43:43.243(225,61):错误CS1503:参数2:无法从“系统属性[]”转换为“系统属性”2017-02-12T00:43:43.243(161,13):警告CS0162:检测到无法访问的代码2017-02-12T00:43:43.243(191,17):警告CS0162:检测到无法访问的代码2017-02-12T00:43:43.243功能已完成(失败,Id=6d48c79d-5af3-4c9a-b4ab-242d186e7c33)顺便说一句,我认为单击“运行”应该总是尝试编译csx文件。目前它没有。只有在触发时,我才会出现上述编译错误。您调用了错误的Binder方法-请再次查看示例代码。它是BindAsync。您应该将方法签名更改为“异步任务”来使用该方法。
{
  Container: "test",
  First: "test1",
  Second: "test2"
}