Azure function error - Cannot bind parameter to String

I am trying to save files to FTP using Azure Function. Json:

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

      

Function code:

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'm getting is this:

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

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

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

      

Why? Can't change path from code?

+3


source to share


1 answer


folder

is an input parameter to your function, it cannot affect the pin binding.

What the syntax means {folder}

is that the runtime will try to find a property folder

on your input element and bind to it.

So try this:

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 it here under "Binding Expressions and Templates" and "Bind to Custom Input Properties in the Binding Context".

+1


source







All Articles