英文:
Azure Functions - BlobTrigger - How to trigger function with any file in a container?
问题
I'm facing a problem with an Azure Function.
我正在遇到Azure函数的问题。
I've build an Azure Function triggered by a new file on a container of a storage account.
The problem is that it seems impossible (to me) to trigger the function with a generic file, without specifing a name!
我已经创建了一个由存储账户容器中的新文件触发的Azure函数。
问题是,似乎不可能(对我来说)触发一个没有指定名称的通用文件的函数!
I've searched on official documentation and it's not specified how to reference a generic file. The expected behaviour is to have a function triggered when I upload any file (with any name) in a specific container, something like "container/*".
我已经在官方文档中搜索过,但没有指定如何引用通用文件。期望的行为是在特定容器中上传任何文件(具有任何名称)时触发函数,类似于"container/*"。
This is my simple function:
这是我的简单函数:
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")
I've already tried using an event on EventGrid, but I prefer avoiding it...
我已经尝试过在EventGrid上使用事件,但我更倾向于避免它...
Can you please help me?
你能帮助我吗?
Thanks in advance!!
提前感谢您!
英文:
I'm facing a problem with an Azure Function.
I've build an Azure Function triggered by a new file on a container of a storage account.
The problem is that it seems impossible (to me) to trigger the function with a generic file, without specifing a name!
I've searched on official documentation and it's not specified how to reference a generic file. The expected behaviour is to have a function triggered when I upload any file (with any name) in a specific container, something like "container/*".
This is my simple function:
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")
I've already tried using an event on EventGrid, but I prefer avoiding it...
Can you please help me?
Thanks in advance!!
答案1
得分: 2
我尝试将通用文件上传到容器中,如下所示,我的函数已被触发。如果您将路径 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"
}
]
}
容器-
日志-
英文:
I have tried to upload generic files to a container as below and my function got triggered. If you will change the path premium-input/*
to premium-input/{name}
, it will work.
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"
}
]
}
Container-
Logs-
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论