2017-07-28 84 views
2

我試圖通過使用Azure函數將文件保存到FTP。 JSON的是這樣的:Azure函數錯誤 - 無法將參數綁定到字符串

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

如果我更換{文件夾}與文件夾命名作品:

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

爲什麼?是否無法更改代碼的路徑?

回答

1

folder是您的函數的輸入參數,它不會影響輸出綁定。

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

function.json

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

你可以閱讀更多here,在「綁定表達式和模式」和「綁定到自定義輸入性的結合表達「部分。

+0

它的工作原理! :)你在哪裏閱讀過這些東西......我沒有在文檔中看到它......或者我錯過了它...... –

+1

@AlexAlbu添加了一個鏈接到我的答案。這不是很詳細,但有一個例子。 – Mikhail

相關問題