0

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.

2
  • When using IBinder you should not have a mapped parameter in your function.json file for that parameter. That's why you're getting the error. Commented Sep 26, 2016 at 20:10
  • File triggers based on files added to a sub folder of a root folder is not supported and you will need to have a different function/trigger on each sub folder. Commented Sep 26, 2016 at 20:16

1 Answer 1

0

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.

Sign up to request clarification or add additional context in comments.

4 Comments

How often does the file watcher look for new files within that folder?
The default is 90 seconds, but you can configure that in your binding via the pollIntervalInSeconds property. The Functions portal doesn't expose that, you'll have to set that via the Advanced Editor.
I removed the out binding and got the following: 2016-09-27T15:45:23.898 Function started (Id=8db8fc1e-69de-4094-9bd4-a90a64ad0199) 2016-09-27T15:45:23.914 Writing to InputTest/SubFolder/fileName.txt... 2016-09-27T15:45:24.008 Function completed (Failure, Id=8db8fc1e-69de-4094-9bd4-a90a64ad0199) 2016-09-27T15:45:24.039 Exception while executing function: Functions.BlogTriggerOutputTest. mscorlib: Exception has been thrown by the target of an invocation. mscorlib: The given key was not present in the dictionary.
Can you please include your full function code as well as the function.json file, if you still get this error?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.