2017-07-28 6 views
2

Azure関数を使用してファイルをFTPに保存しようとしています。 JSONはこれです:Azure関数のエラー - パラメーターをString型にバインドできません。

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

機能コードはこれです:私は、フォルダ名とそれを{フォルダ}を交換する場合

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

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

} 

私が手にエラーがこれです作品:

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

なぜですか?コードからパスを変更することはできませんか?

答えて

1

folderは、関数の入力パラメータであり、出力結合に影響を与えることはできません。

{folder}とは、ランタイムが入力項目にfolderというプロパティを見つけようとすることを意味します。

だからではなく、次の試してください。function.json

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

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

あなたは「バインディング式やパターン」で、here続きを読むと「結合でカスタム入力プロパティにバインドすることができます「発現」セクション。

+0

これは機能します。 :)この資料をどこで読んだのですか...私はドキュメントでそれを見なかった...または多分私はそれを逃した... –

+1

@AlexAlbu私の答えへのリンクを追加しました。それはあまり詳細ではありませんが、例があります。 – Mikhail

関連する問題