Azure函数-Blob流动态输入绑定 [英] Azure Functions - Blob Stream Dynamic Input bindings

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

问题描述

我正在azure上运行C#函数,该函数需要从容器中接收文件.唯一的问题是输入文件的路径每次都会(可能)不同,并且输入文件的数量从1到大约4或5不等.因此,我不能只使用默认的输入Blob绑定据我所知.我的选择是为容器提供匿名访问权限,只需通过链接即可获取文件,或弄清楚如何获取动态输入绑定.

I'm running a C# function on azure which needs to take in files from a container. The only problem is that the paths to the input files are going to be (potentially) different each time, and the number of input files will vary from 1 to about 4 or 5. Accordingly I can't just use the default input blob bindings as far as I'm aware. My options are give the container anonymous access and just grab the files through the link or figure out how to get dynamic input bindings.

有人知道如何在运行时(使用C#代码)声明输入Blob流的路径吗?

Does anyone know how to declare the path for the input blob stream at runtime (in the C# code)?

如果有帮助,我已经设法为动态输出绑定找到了它

If it helps I've managed to find this for dynamic output bindings

using (var writer = await binder.BindAsync<TextWriter>(
                  new BlobAttribute(containerPath + fileName)))
    {
        writer.Write(OutputVariable);
    }

预先感谢,C

推荐答案

对于动态输出绑定,您可以利用以下代码片段:

For dynamic output bindings, you could leverage the following code snippet:

var attributes = new Attribute[]
{    
    new BlobAttribute("{container-name}/{blob-name}"),
    new StorageAccountAttribute("brucchStorage") //connection string name for storage connection
};
using (var writer = await binder.BindAsync<TextWriter>(attributes))
{
    writer.Write(userBlobText);
}

注意:以上代码将创建目标blob(如果不存在),并覆盖现有blob(如果存在).此外,如果您未指定StorageAccountAttribute,则会根据应用程序设置AzureWebJobsStorage在存储帐户中创建目标Blob.

Note: The above code would create the target blob if not exists and override the existing blob if it exists. Moreover, if you do not specify the StorageAccountAttribute, your target blob would be create into the storage account based on the app setting AzureWebJobsStorage.

此外,您可以按照 Azure Functions命令性绑定进行详细了解

Additionally, you could follow Azure Functions imperative bindings for more details.

更新:

对于动态输入绑定,您可以如下更改绑定类型:

For dynamic input binding, you could just change the binding type as follows:

var blobString = await binder.BindAsync<string>(attributes);

或者您可以将绑定类型设置为CloudBlockBlob并为Azure存储Blob添加以下名称空间:

Or you could set the binding type to CloudBlockBlob and add the following namespace for azure storage blob:

#r "Microsoft.WindowsAzure.Storage"
using Microsoft.WindowsAzure.Storage.Blob;

CloudBlockBlob blob = await binder.BindAsync<CloudBlockBlob>(attributes);

此外,有关CloudBlockBlob操作的更多详细信息,您可以遵循

Moreover, more details about the operations for CloudBlockBlob, you could follow here.

这篇关于Azure函数-Blob流动态输入绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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