c# - Azure函数版本2.0-应用程序blobTrigger不工作

标签 c# azure azure-functions azure-blob-storage

我有一个工作函数应用程序,它有一个 blob 输入和一个事件中心输出(在测试版中工作)。 随着最新的更改,我的功能不再起作用。 我尝试根据发行说明更新 host.json 文件,但它没有引用 blob 触发器:

{


"version": "2.0",
  "extensions": {
      "blobTriggers" : {
        "name": "blob",
        "type": "blobTrigger",
        "direction": "in",
        "path": "iot3gblobs/{name}",
        "connection": "AzureWebJobsStorage"
      },

      "eventHubs": {
        "type": "eventHub",
        "name": "outputEventHubMessages",
        "path": "ioteventhub",
        "connection": "IoTEventHubConnection",
        "cardinality": "many",
        "direction": "out"
      }
    },
    "Host" : 
    {
      "LocalHttpPort": 7071,
      "CORS": "*"
    },
  "disabled": false
}

另外,升级时 Microsoft.NET.Sdk.Functions 从 1.0.14 到 1.0.19 blobTrigger 属性无法识别,我的代码将无法编译:

[FunctionName("iotserverparser")]
        public async static Task Run(
            [BlobTrigger("iot3gblobs/{name}", Connection = "AzureWebJobsStorage")]
            Stream blob,
            [EventHub(
                "outputEventHubMessages", Connection =
                    "IoTEventHubConnection")]

如前所述,这是由于上次 Azure Function App 更新造成的,我还没有看到任何有关如何在这个新的 2.0 版本中使用 Blob 触发器的示例。

最佳答案

要将 Azure Function 与 Blob 文件更新连接,请执行以下步骤。

  1. 单击“功能”菜单中的“+”图标。

    enter image description here

  2. 然后选择“Azure Blob 存储触发器”:

    enter image description here

  3. 弹出窗口/侧边栏打开后,您需要填写 Blob 相关信息。
    这非常简单,但首先,单击"new"链接,它将弹出另一个 View ,您可以在其中查看存储帐户列表。

    enter image description here

  4. 从列表中,确保选择您想要收到通知的确切存储帐户。

  5. 之后您将看到存储名称出现在“存储帐户连接”输入框下方(您还可能会看到存储名称末尾附加了一些附加标签,例如“..._STORAGE”,没关系) .

  6. 除了帐户连接之外,您还需要提供容器名称,您可以通过查看存储帐户的“Blob”部分找到该名称。

    enter image description here

  7. 现在创建 blob 触发器之前的最终外观应该是:

    enter image description here

Here make sure you don't touch the {name} part under the Path input. That variable is needed to reflect the changed file/blob name.

  • 最后,单击“创建”按钮,然后尝试上传 Blob 容器中的任何文件。 您应该看到代表更改的日志。 enter image description here
  • <小时/>

    此外,就是这样,不需要额外的引用 (#r) 或 using 来查看 blob 更改。

    Note that blob changes might reflect with a bit delay under the Logs section. However, if after some time you still don't see any updates there then check once more that you have provided correct Storage Account and container names. To do that you might need to create the blob trigger again.

    关于c# - Azure函数版本2.0-应用程序blobTrigger不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52148588/

    相关文章:

    visual-studio - 启动Azure Function时,不要自动启动模拟器等

    c# - 如何使用azure函数应用程序读取azure blob中的内容

    c# - Request.Browser.IsMobileDevice 不适用于 iPadAir2 和 iOS 13.0.1

    c# - 在 c# 中向应用程序发送击键(sendkeys、postmessage、sendmessage 都不起作用)

    .net - Azure服务总线: all topic subscribers must process message

    c# - 隐藏/加密 Azure 数据工厂项目中的密码和 key

    azure - ADF 映射数据流 - 脏/标签替换/接收器缓存和派生列

    C# HttpClient 和 Windows 身份验证 : Cannot access a closed Stream

    javascript - 检查参数的更好方法?

    azure - Team Foundation 服务自动构建和测试数据库错误