gpt4 book ai didi

c# - Azure Functions 错误 - 无法将参数绑定(bind)到字符串类型

转载 作者:行者123 更新时间:2023-11-30 12:21:33 25 4
gpt4 key购买 nike

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

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

}

我得到的错误是这样的:

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.).

如果我将 {folder} 替换为文件夹名称,则它可以工作:

"path": "psm/ps-{DateTime}.txt"
为什么?不能从代码中更改路径吗?

最佳答案

folder 是函数的输入参数,它不会影响输出绑定(bind)。

{folder} 语法的含义是运行时将尝试在输入项中查找 folder 属性,并绑定(bind)到它。

因此请尝试以下操作:

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

您可以阅读更多here ,在“绑定(bind)表达式和模式”和“绑定(bind)到绑定(bind)表达式中的自定义输入属性”部分。

关于c# - Azure Functions 错误 - 无法将参数绑定(bind)到字符串类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45371396/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com