python - Azure Functions - BlobTrigger - 如何使用容器中的任何文件触发函数?

标签 python azure azure-functions azure-blob-storage event-driven

我在使用 Azure 函数时遇到问题。

我已经构建了一个由存储帐户容器上的新文件触发的 Azure 函数。 问题是(对我来说)似乎不可能在不指定名称的情况下使用通用文件触发该函数!

我搜索过官方文档,但没有指定如何引用通用文件。预期的行为是当我在特定容器(例如“container/*”)中上传任何文件(具有任何名称)时触发一个函数。

这是我的简单功能:

function.json

{
  "scriptFile": "__init__.py",
  "bindings": [
    {
      "name": "inputBlob",
      "type": "blobTrigger",
      "direction": "in",
      "path": "premium-input/*",
      "connection": "AzureWebJobsStorage"
    }
  ]
}

init.py

import logging
import azure.functions as func


def main(inputBlob: func.InputStream):
    logging.info("START EXECUTION")
    logging.info(f'NAME {inputBlob.name}')
    logging.info(f'URI {inputBlob.uri}')
    logging.info("END EXECUTION")

我已经尝试过在 EventGrid 上使用事件,但我更愿意避免它...

你能帮我吗?

提前致谢!!

最佳答案

我尝试将通用文件上传到容器,如下所示,我的函数被触发。如果您将路径 premium-input/* 更改为 premium-input/{name} ,它将起作用。

init.py

import logging
import azure.functions as func
def main(myblob: func.InputStream):
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"URI: {myblob.uri}\n"
f"Blob Size: {myblob.length} bytes")

function.json

{
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "demo/{name}",
"connection": "your connection string"
}
]
} 

容器- enter image description here

日志- enter image description here

enter image description here

关于python - Azure Functions - BlobTrigger - 如何使用容器中的任何文件触发函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76326040/

相关文章:

asp.net-mvc - 如何使用 signalr 将多个客户端连接到同一个 websocket?

c# - Azure Restful Web 服务

python - 如何在整个代码中使用 __init__ 方法中定义的变量?

python - 电源 BI : How to use Python with multiple tables in the Power Query Editor?

python - 删除 Pandas 方差低的列

azure - 无法通过 RDP 访问 Azure VM - 用户/组问题

c# - Azure队列触发器错误地给出空队列项目

c# - Azure function 2.x ILogger 与.net core ILogger 不兼容?

azure - Azure Function 方法名称重要吗?

Python Altair 绘制两个偏差标准