问题
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