Azure Function blob binding

后端 未结 1 881
长情又很酷
长情又很酷 2021-01-13 20:55

I\'m not able to bind an input parameter of type blob to either string/TextReader without using the [BlobAttribute] in a C# implementation (not CSX).

The error I\'m

相关标签:
1条回答
  • 2021-01-13 21:08

    The issue turned out to be with the latest runtime supporting a new property (configurationSource) in function.json

    This tells the runtime to use either config (which is function.json) or C# attributes for function config.

    essentially allowing you to either define your function like this

    Now you can either define your function as

    [FunctionName("Harvester")]
    public static async Task Run(
        [TimerTrigger]TimerInfo myTimer,
        TraceWriter log,
        TextReader configReader)
    {
    }
    

    along with a function.json that looks like this

    {
      "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
      "configurationSource": "config",
      "bindings": [
        {
          "type": "timerTrigger",
          "schedule": "0 */5 * * * *",
          "useMonitor": true,
          "runOnStartup": false,
          "direction": "in",
          "name": "myTimer"
        },
        {
          "type": "blob",
          "name": "configReader",
          "path": "secured/app.config.json",
          "connection": "XXX",
          "direction": "in"
        }
      ],
      "disabled": false,
      "scriptFile": "...",
      "entryPoint": "..."
    }
    

    or like this

    [FunctionName("Harvester")]
    public static async Task Run(
        [TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
        TraceWriter log,
        [Blob("secured/app.config.json", FileAccess.Read)]TextReader configReader)
    {
    }
    

    with a simpler config like this

    {
      "generatedBy": "Microsoft.NET.Sdk.Functions-1.0.0.0",
      "configurationSource": "attributes",
      "bindings": [
        {
          "type": "timerTrigger",
          "name": "myTimer"
        },
      ],
      "scriptFile": "...",
      "entryPoint": "..."
    }
    

    note the value of configurationSource in both examples.

    The tooling for Visual Studio 2017 does the latter by default. If you wanna change your function.json to include all your config and change the configurationSource you will need to include the file in your project and mark it as always copy. This GIF shows how to do that.

    0 讨论(0)
提交回复
热议问题