我正在尝试使用 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}");
}
我得到的错误是这样的:
函数($SaveToFtp)错误:Microsoft.Azure.WebJobs.Host:错误
索引方法“Functions.SaveToFtp”。 Microsoft.Azure.WebJobs.Host:
无法将参数“文件夹”绑定到字符串类型。确保参数
绑定支持类型。如果您使用绑定扩展
(例如 ServiceBus、定时器等)确保您已调用
启动代码中扩展的注册方法(例如
config.UseServiceBus()、config.UseTimers() 等)。
如果我将 {folder} 替换为文件夹名称,则它可以工作:
"path": "psm/ps-{DateTime}.txt"
为什么?难道不能从代码中改变路径吗?
folder
是函数的输入参数,它不会影响输出绑定。
What {folder}
语法意味着运行时将尝试查找folder
输入项中的属性,并绑定到它。
因此请尝试以下方法:
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"
}
您可以阅读更多内容here https://learn.microsoft.com/en-us/azure/azure-functions/functions-triggers-bindings,在“绑定表达式和模式”和“绑定到绑定表达式中的自定义输入属性”部分。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)