有几种不同的方法可以完成此操作。首先,如果需要输出的斑点数量为固定为,则可以使用多个输出绑定。
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有效载荷的功能,和斑点产生:
{
Container: "test",
First: "test1",
Second: "test2"
}
的上面的示例演示了如何从输入中绑定Blob容器/名称值(通过{Container}/{First}
{Container}/{Second}
路径表达式)。你只需要定义一个POCO来捕获你想要绑定的值。我在这里使用ManualTrigger是为了简单起见,但它也适用于其他触发器类型。此外,虽然我选择了绑定到out string
类型,可以绑定到任何其他支持的类型:TextWriter
,Stream
,CloudBlockBlob
等
如果需要输出斑点的数量是变量,那么你可以使用Binder来强制绑定和写入功能代码中的斑点。有关更多详细信息,请参见here。要绑定到多个输出,您只需使用该技术执行多个命令式绑定。
FYI:我们的文档是不正确的,所以我记录一个错误here得到固定,:)
我想的是势在必行的模式。我得到一个编译错误 - 见下文。 –
//命令式绑定到存储 blobPath = $“json/{fileNamePart} _ {dateString}”; var attributes = new Attribute [] { new BlobAttribute(blobPath), new StorageAccountAttribute(storageAccount) }; using(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):error CS1026:)expected 2017-02-12T00:43:43.243(225,61):error CS1503:Argument 2:无法从'System.Attribute []'转换为' System.Attribute' 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) –