本文介绍了Azure函数错误-无法将参数绑定到字符串类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Azure函数将文件保存到FTP.json是这样的:

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"
}

功能代码是这样的:

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}");

}

我得到的错误是:

如果我将{folder}替换为文件夹名称,它将起作用:

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?

推荐答案

文件夹是函数的输入参数,它不会影响输出绑定.

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

{folder} 语法的含义是,运行时将尝试在输入项中找到 folder 属性并将其绑定.

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}";
}

带有 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.

这篇关于Azure函数错误-无法将参数绑定到字符串类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-24 07:23