4

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 Answer 1

2

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.

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

2 Comments

It works! :) Where did you read this stuff... I did not see it in the docs... or maybe I missed it...
@AlexAlbu Added a link to my answer. It's not very detailed, but has an example.

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.