<legend id='d3xVP'><style id='d3xVP'><dir id='d3xVP'><q id='d3xVP'></q></dir></style></legend>
    • <bdo id='d3xVP'></bdo><ul id='d3xVP'></ul>

        <tfoot id='d3xVP'></tfoot>
      1. <i id='d3xVP'><tr id='d3xVP'><dt id='d3xVP'><q id='d3xVP'><span id='d3xVP'><b id='d3xVP'><form id='d3xVP'><ins id='d3xVP'></ins><ul id='d3xVP'></ul><sub id='d3xVP'></sub></form><legend id='d3xVP'></legend><bdo id='d3xVP'><pre id='d3xVP'><center id='d3xVP'></center></pre></bdo></b><th id='d3xVP'></th></span></q></dt></tr></i><div id='d3xVP'><tfoot id='d3xVP'></tfoot><dl id='d3xVP'><fieldset id='d3xVP'></fieldset></dl></div>

      2. <small id='d3xVP'></small><noframes id='d3xVP'>

        Azure 函数 blob 绑定

        时间:2023-10-05
        • <bdo id='XLBbt'></bdo><ul id='XLBbt'></ul>

            <small id='XLBbt'></small><noframes id='XLBbt'>

                <tbody id='XLBbt'></tbody>
            1. <tfoot id='XLBbt'></tfoot>
            2. <legend id='XLBbt'><style id='XLBbt'><dir id='XLBbt'><q id='XLBbt'></q></dir></style></legend>
              <i id='XLBbt'><tr id='XLBbt'><dt id='XLBbt'><q id='XLBbt'><span id='XLBbt'><b id='XLBbt'><form id='XLBbt'><ins id='XLBbt'></ins><ul id='XLBbt'></ul><sub id='XLBbt'></sub></form><legend id='XLBbt'></legend><bdo id='XLBbt'><pre id='XLBbt'><center id='XLBbt'></center></pre></bdo></b><th id='XLBbt'></th></span></q></dt></tr></i><div id='XLBbt'><tfoot id='XLBbt'></tfoot><dl id='XLBbt'><fieldset id='XLBbt'></fieldset></dl></div>

                  本文介绍了Azure 函数 blob 绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  如果不使用 C# 实现(不是 CSX)中的 [BlobAttribute],我无法将 blob 类型的输入参数绑定到字符串/TextReader.

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

                  我得到的错误是:

                  Microsoft.Azure.WebJobs.Host: Error indexing method 'Functions.Harvester'. 
                  Microsoft.Azure.WebJobs.Host: Cannot bind parameter 'configReader' to type 
                  TextReader. 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.).
                  

                  function.config:

                  function.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"
                      }
                    ],
                  

                  函数签名(不绑定configReader):

                  [FunctionName("Harvester")]
                   public static async Task Run(
                     [TimerTrigger("0 */5 * * * *")]TimerInfo myTimer,
                     TraceWriter log,
                     TextReader configReader)
                  

                  尽管如此(BINDING configReader:

                  This would work though (BINDING configReader:

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

                  关于如何在不指定 BlobAttribute 中的 blob 路径的情况下使其工作的任何想法.理想情况下,我会将 Blob 配置保留在代码之外,这样我的函数就会变得更加可移植.

                  Any idea on how to get it working without specifying the blob path in BlobAttribute. I'd ideally keep the Blob config outside of the code, that way my function would become more portable.

                  推荐答案

                  问题出在最新的运行时支持 function.json 中的新属性 (configurationSource)代码>

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

                  这告诉运行时使用 config(即 function.json)或 C# 属性进行函数配置.

                  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)
                  {
                  }
                  

                  还有一个看起来像这样的 function.json

                  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": "..."
                  }
                  

                  或者像这样

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

                  像这样更简单的配置

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

                  注意两个示例中 configurationSource 的值.

                  note the value of configurationSource in both examples.

                  Visual Studio 2017 的工具默认执行后者.如果您想更改您的 function.json 以包含您的所有配置并更改 configurationSource 您将需要在您的项目中包含该文件并将其标记为始终复制.这个 GIF 展示了如何做到这一点.

                  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.

                  这篇关于Azure 函数 blob 绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:azure 服务总线的 Azure Function App 延迟重试 下一篇:Azure Function V2 服务总线消息延迟

                  相关文章

                  <i id='npeEC'><tr id='npeEC'><dt id='npeEC'><q id='npeEC'><span id='npeEC'><b id='npeEC'><form id='npeEC'><ins id='npeEC'></ins><ul id='npeEC'></ul><sub id='npeEC'></sub></form><legend id='npeEC'></legend><bdo id='npeEC'><pre id='npeEC'><center id='npeEC'></center></pre></bdo></b><th id='npeEC'></th></span></q></dt></tr></i><div id='npeEC'><tfoot id='npeEC'></tfoot><dl id='npeEC'><fieldset id='npeEC'></fieldset></dl></div>
                • <legend id='npeEC'><style id='npeEC'><dir id='npeEC'><q id='npeEC'></q></dir></style></legend>

                  <small id='npeEC'></small><noframes id='npeEC'>

                    <tfoot id='npeEC'></tfoot>
                      <bdo id='npeEC'></bdo><ul id='npeEC'></ul>