4
votes

I am trying to save files to FTP by using an Azure Function. The json is this:

{
      "type": "apiHubFile",
      "name": "outputFile",
      "path": "{folder}/ps-{DateTime}.txt",
      "connection": "ftp_FTP",
      "direction": "out"
}

The function code is this:

public static void Run(string myEventHubMessage, TraceWriter log, string folder, out string outputFile)
{
    var model = JsonConvert.DeserializeObject<PalmSenseMeasurementInput>(myEventHubMessage);

    folder = model.FtpFolderName;

    outputFile = $"{model.Date.ToString("dd.MM.yyyy hh:mm:ss")};{model.Concentration};{model.Temperature};{model.ErrorMessage}";


    log.Info($"C# Event Hub trigger Save-to-ftp function saved to FTP: {myEventHubMessage}");

}

The error I get is this:

Function ($SaveToFtp) Error: Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.SaveToFtp'. Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'folder' to type String. Make sure the parameter Type is supported by the binding. If you're using binding extensions (e.g. ServiceBus, Timers, etc.) make sure you've called the registration method for the extension(s) in your startup code (e.g. config.UseServiceBus(), config.UseTimers(), etc.).

If I replace {folder} with a folder name it works:

"path": "psm/ps-{DateTime}.txt"

Why? Is it not possible to change the path from the code?

1

1 Answers

2
votes

folder is an input parameter of your function, it can't affect the ouput binding.

What {folder} syntax means is that the runtime will try to find folder property in your input item, and bind to it.

So try the following instead:

public static void Run(PalmSenseMeasurementInput model, out string outputFile)
{
    outputFile = $"{model.Date.ToString("dd.MM.yyyy hh:mm:ss")};{model.Concentration};{model.Temperature};{model.ErrorMessage}";
}

with function.json:

{
      "type": "apiHubFile",
      "name": "outputFile",
      "path": "{FtpFolderName}/ps-{DateTime}.txt",
      "connection": "ftp_FTP",
      "direction": "out"
}

You can read more here, in "Binding expressions and patterns" and "Bind to custom input properties in a binding expression" sections.