How can I set a folder name and file name in Azure Functions SaaS File bindings?

痞子三分冷 提交于 2019-12-25 09:16:04

问题


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.

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.


UPDATE

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...");
}

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.


回答1:


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}.

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



来源:https://stackoverflow.com/questions/39669606/how-can-i-set-a-folder-name-and-file-name-in-azure-functions-saas-file-bindings

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!