如何在Azure Functions SaaS文件绑定中设置文件夹名称和文件名? [英] How can I set a folder name and file name in Azure Functions SaaS File bindings?

查看:90
本文介绍了如何在Azure Functions SaaS文件绑定中设置文件夹名称和文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用SaaS文件触发器来侦听FTP站点中的新文件.首先,您甚至可以定义一个变量文件夹,例如"path": "inputTest/{folder}/{fileName}"吗?或者,也许听所有子文件夹中的新文件,并在文件名中包含路径,例如inputTest/{file},其中file可能等于"subfolder/fileName.txt"?这里的想法是,我将有多个客户端将文件上传到他们自己的目录中,并且我不想为每个客户端创建一个新的函数/触发器.

I am trying to use a SaaS File trigger to listen for new files in an FTP site. First of all, can you even define a variable folder, like "path": "inputTest/{folder}/{fileName}"? Or, perhaps, listen to new files in all subfolders and include the path in the file name, like inputTest/{file} where file might equal "subfolder/fileName.txt"? The idea here is that I will have multiple clients uploading files into their own directories, and I don't want to create a new function/trigger for each one.

输出内容相同.我想要一个可以写入各种文件夹的SasS文件绑定.我想我可以使用此处所述的方法,但我仍然需要对其进行测试.我的想法是我要流式传输输入文件,一次读取一行,以某种方式处理该行,然后将其写到另一个文件中.本质上是一种转变.可能还有其他方法可以做到这一点,但我想更好地理解这种绑定.

The same thing goes for the output. I want a SasS File binding that can write to various folders. I think I can use the method described here, but I'll still need to test it out. The idea is that I want to stream the input file reading a line at a time, process the line in some way, and write it out to another file. Essentially a transform. There might be other ways to do this but I would like to understand this binding better.

更新

我尝试了以下方法进行输出绑定:

I tried the following for the output binding:

using System;
using Microsoft.Azure.WebJobs;

public static void Run(string input, IBinder output, TraceWriter log)
{
    string connectionStringSetting = Environment.GetEnvironmentVariable(
        "ftp_FTP", EnvironmentVariableTarget.Process);
    var path = "InputTest/SubFolder/fileName.txt";
    log.Info($"Writing to {path}...");
    using (var writer = output.Bind<TextWriter>(
        new ApiHubFileAttribute(connectionStringSetting, path)))
    {
        writer.Write(input);
    }
    log.Info("Done writing...");
}

我包括了ApiHubFileAttributeMicrosoft.Azure.WebJobs.Extensions.ApiHub NuGet软件包.我收到错误Exception binding parameter 'output'. Microsoft.Azure.WebJobs.Extensions.ApiHub: Unsupported type:Microsoft.Azure.WebJobs.IBinder.任何帮助将不胜感激.

I included the Microsoft.Azure.WebJobs.Extensions.ApiHub NuGet package for the ApiHubFileAttribute. I got the error Exception binding parameter 'output'. Microsoft.Azure.WebJobs.Extensions.ApiHub: Unsupported type:Microsoft.Azure.WebJobs.IBinder. Any help would be appreciated.

推荐答案

SaaS文件触发器绑定不处理对变量子路径的监视.路径表达式的格式必须为folder/{fileName},并且文件组件将仅绑定到该特定文件夹中的单个文件,而不会绑定到子文件夹.文件名之前的静态路径可以包含子文件夹,例如folder/subFolder/{fileName}.

The SaaS file trigger binding does not handle monitoring of variable sub paths. The path expression must be of the form folder/{fileName} and the file component will only bind to individual files in that specific folder, not sub folders. The static path before the file name can include sub folders, e.g. folder/subFolder/{fileName}.

您可以按照描述的方式使用IBinder来写入一个或多个文件.那应该起作用.

You can use IBinder in the way you describe to write one or more files. That should work.

这篇关于如何在Azure Functions SaaS文件绑定中设置文件夹名称和文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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