如何从Azure函数输出多个Blob? [英] How to output multiple blobs from an Azure Function?

查看:96
本文介绍了如何从Azure函数输出多个Blob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输出绑定具有示例:

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.

集成"用户界面中的默认设置为:

And default in "Integrate" UI has default as:

Path: outcontainer/{rand-guid}

但这不足以让我取得进展.如果我使用C#编码,那么function.json和run.csx将多个Blob输出到一个容器的语法是什么?

But this isn't sufficient for me to make headway. If I'm coding in C#, what is the syntax for function.json and for run.csx to output multiple blobs to a container?

推荐答案

有几种不同的方法可以完成此操作.首先,如果您需要输出的Blob的数量是固定的,则可以使用多个输出绑定.

There are several different ways you can accomplish this. First, if the number of blobs you need to output is fixed, you can just use multiple output bindings.

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:

And the corresponding 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:

To test the above, I send a test JSON payload to the function, and the blobs are generated:

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

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

The sample above demonstrates how the blob container/name values can be bound from the input (via the {Container}/{First} {Container}/{Second} path expressions). You just have to define a POCO capturing the values you want to bind to. I used ManualTrigger here for simplicity, but this works for the other trigger types as well. Also, while I chose to bind to out string Types, you can bind to any of the other supported types: TextWriter, Stream, CloudBlockBlob, etc.

如果您需要输出的Blob的数量是可变的,则可以使用 Binder 强制性地在函数代码中绑定和写入Blob.参见此处以获取更多详细信息.要绑定到多个输出,只需使用该技术执行多个命令式绑定即可.

If the number of blobs you need to output is variable, then you can use Binder to imperatively bind and write blobs in your function code. See here for more details. To bind to multiple outputs, you'd just perform multiple imperative bindings using that technique.

仅供参考:我们的文档不正确,所以我在此处记录了一个错误得到修复:)

FYI: our documentation was incorrect, so I logged a bug here to get that fixed :)

这篇关于如何从Azure函数输出多个Blob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆