Azure Functions - Blob 流输出绑定 [英] Azure Functions - Blob Stream output binding
问题描述
我创建了一个带有 blob 存储触发器的 Azure 函数 - 我想处理一个文件,然后将文件转储到另一个 blob 存储容器.
I've created an Azure function with a blob storage trigger - I want to process a file and then dump the file out to another blob storage container.
在最简单的情况下,我想它看起来像这样:
In the simplest case I suppose it would look like this:
public static void Run(Stream blob, string name, out Stream outputBlob, TraceWriter log)
{
outputBlob = blob;
}
这些是我的绑定:
{
"bindings": [
{
"name": "blob",
"type": "blobTrigger",
"direction": "in",
"path": "input/{name}",
"connection": "wlimportstaging_STORAGE"
},
{
"name": "outputBlob",
"type": "blob",
"direction": "out",
"path": "original/{name}",
"connection": "wlimportstaging_STORAGE"
}
],
"disabled": false
}
我从文档中了解到,如果您返回一个 POCO,它将把它序列化为 JSON.
I've read from the documentation that if you return a POCO it will serialize it as JSON.
https:///docs.microsoft.com/en-us/azure/azure-functions/functions-bindings-storage-blob#output-usage
这似乎表明您可以输出到流 - 我似乎得到了:
This seems to suggest you can output to a stream - I just seem to be getting:
Microsoft.Azure.WebJobs.Host:无法将 Blob 绑定到类型System.IO.Stream&
请帮忙!
推荐答案
这很好.如果有更好的方法,我会很感兴趣.
This worked fine. If there is a better approach I would be really interested.
public static async Task Run(Stream blob, string name, Stream outBlob, TraceWriter log)
{
using (MemoryStream ms = new MemoryStream())
{
blob.CopyTo(ms);
var byteArray = ms.ToArray();
await outBlob.WriteAsync(byteArray, 0, byteArray.Length);
}
}
这篇关于Azure Functions - Blob 流输出绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!