2017-02-11 20 views
2

は例があります。Azure関数から複数のブロブを出力するには?バインディングアウト

ICollector<T> (to output multiple blobs) 

も:

Path: outcontainer/{rand-guid} 

しかし、これは私のために十分ではありません:UIは、デフォルトを持っている "統合" で

Path must contain the container name and the blob name to write to. For example, 
if you have a queue trigger in your function, you can use "path": 
"samples-workitems/{queueTrigger}" to point to a blob in the samples-workitems 
container with a name that matches the blob name specified in the trigger 
message. 

とデフォルト頭を下げる。私がC#でコーディングしているのであれば、function.jsonの構文とrun.csxのコンテナに複数のblobを出力する構文は何ですか?

答えて

0

これを達成するにはいくつかの方法があります。まず、出力する必要があるブロブの数がの場合、と固定されていれば、複数の出力バインディングを使用できます。

using System; 

public class Input 
{ 
    public string Container { get; set; } 
    public string First { get; set; } 
    public string Second { get; set; } 
} 

public static void Run(Input input, out string first, out string second, TraceWriter log) 
{ 
    log.Info($"Writing 2 blobs to container {input.Container}"); 
    first = "Azure"; 
    second = "Functions"; 
} 

および対応function.json:

{ 
    "bindings": [ 
    { 
     "type": "manualTrigger", 
     "direction": "in", 
     "name": "input" 
    }, 
    { 
     "type": "blob", 
     "name": "first", 
     "path": "{Container}/{First}", 
     "connection": "functionfun_STORAGE", 
     "direction": "out" 
    }, 
    { 
     "type": "blob", 
     "name": "second", 
     "path": "{Container}/{Second}", 
     "connection": "functionfun_STORAGE", 
     "direction": "out" 
    } 
    ] 
} 

上記をテストするために、私は関数にテストJSONペイロードを送信し、ブロブが生成される:

{ 
    Container: "test", 
    First: "test1", 
    Second: "test2" 
} 

上のサンプルは、BLOBコンテナ/名前の値が({Container}/{First}{Container}/{Second}のパス式を使用して)入力からバインドされる方法を示しています。バインドする値をキャプチャするPOCOを定義するだけです。私はManualTriggerをここでは単純化のために使用しましたが、これは他のトリガータイプでも機能します。また、私はout stringタイプにバインドすることを選んだが、あなたはサポートされている他のタイプのいずれかに特異的に結合することができます:TextWriterStreamCloudBlockBlobなど

あなたが出力に必要なブロブの数が変数であれば、あなたはバインダーを使用すると、ファンクションコードにBLOBを強制的にバインドして書き込むことができます。詳細は、hereを参照してください。複数の出力にバインドするには、その手法を使用して複数の必須バインディングを実行するだけです。

はFYI:私たちのドキュメントが間違っていたので、私は私が不可欠パターンことをしようとしていますその固定:)

+0

を取得するために、バグhereをログに記録しました。コンパイルエラーが発生しました - 下記を参照してください。 –

+0

//ストレージへの必須バインド blobPath = $ "json/{fileNamePart} _ {dateString}"; var attributes = new Attribute [] { 新しいBlobAttribute(blobPath)、 新しいStorageAccountAttribute(storageAccount) }; using(var writer = binder.Bind (属性)){ writer.Write(jsonString.ToString()); } –

+0

エラー: 2017-02-12T00:43:43:43.243関数コンパイルエラー 2017-02- 43.243機能(ID = 6d48c79d-5af3-4c9a-b4ab-242d186e7c33) 2017-02-12T00開始しましたエラーCS1503:引数2: 'System.Attribute []'から 'System.Attribute []'に変換できません。 System.Attribute ' 2017-02-12T00:43:43.243(161,13):警告CS0162:到達不能コードが検出されました 2017-02-12T00:43:43。243(191,17):警告CS0162:43:到達不能コードは 2017-02-12T00を検出完了43.243機能(故障、ID = 6d48c79d-5af3-4c9a-b4ab-242d186e7c33) –

関連する問題