admin管理员组文章数量:1414628
I'm trying to implement azure blob trigger in python. So whenever a file gets uploaded, blob trigger should read those files and apply logic over those file's data.
File is getting uploaded into the container but blob trigger is not working.
I've gone through official documentation Azure Blob storage trigger for Azure Functions
function.json
{
"name": "upload_file",
"entryPoint": "upload_file",
"scriptFile": "function_app.py",
"language": "python",
"functionDirectory": "/home/site/wwwroot",
"bindings": [
{
"direction": "IN",
"type": "blobTrigger",
"name": "client",
"path": "<container-name>/{name}",
"connection": "<storage account connection string>"
}
]
}
Blob Trigger Code
connection_string = os.getenv('BLOB_ENDPOINT')
container_name = os.getenv('BLOB_CONTAINER')
@app.function_name(name="upload_file")
@app.blob_trigger(
arg_name="client", path=f"{container_name}/{{name}}", connection=connection_string
)
def upload_file(client: func.InputStream):
"""Handle Excel file upload and manage Cosmos DB containers."""
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {client.name}\n"
f"Blob Size: {client.length} bytes")
also configured environment variables in azure function.
local.setting.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<storage account connection string>",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
}
}
Thanks in advance
I'm trying to implement azure blob trigger in python. So whenever a file gets uploaded, blob trigger should read those files and apply logic over those file's data.
File is getting uploaded into the container but blob trigger is not working.
I've gone through official documentation Azure Blob storage trigger for Azure Functions
function.json
{
"name": "upload_file",
"entryPoint": "upload_file",
"scriptFile": "function_app.py",
"language": "python",
"functionDirectory": "/home/site/wwwroot",
"bindings": [
{
"direction": "IN",
"type": "blobTrigger",
"name": "client",
"path": "<container-name>/{name}",
"connection": "<storage account connection string>"
}
]
}
Blob Trigger Code
connection_string = os.getenv('BLOB_ENDPOINT')
container_name = os.getenv('BLOB_CONTAINER')
@app.function_name(name="upload_file")
@app.blob_trigger(
arg_name="client", path=f"{container_name}/{{name}}", connection=connection_string
)
def upload_file(client: func.InputStream):
"""Handle Excel file upload and manage Cosmos DB containers."""
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {client.name}\n"
f"Blob Size: {client.length} bytes")
also configured environment variables in azure function.
local.setting.json
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<storage account connection string>",
"FUNCTIONS_WORKER_RUNTIME": "python",
"AzureWebJobsFeatureFlags": "EnableWorkerIndexing",
}
}
Thanks in advance
Share Improve this question edited Feb 24 at 5:53 jp_m0rgh 172 bronze badges asked Feb 23 at 11:15 sandeep sandysandeep sandy 12 bronze badges 1- Can you check the path specified in the function.json file. Make sure it matches the path where the blobs are being uploaded in your Azure Storage container. – Pavan Commented Feb 24 at 3:02
1 Answer
Reset to default -1azure blob trigger is not working when files uploaded in the storage container
I have created the Blob trigger function with runtime stack Python V1.
When the blob is uploaded into the azure storage container, function got triggered successfully and retrieved the content of the blob.
Function code:
import os
import logging
import azure.functions as func
# Get environment variables for the storage account connection string and container name
connection_string = os.getenv('AzureWebJobsStorage')
container_name = os.getenv('BLOB_CONTAINER')
def main(myblob: func.InputStream):
"""Handle file upload from Blob Storage."""
# Log the details of the uploaded blob
logging.info(f"Python blob trigger function processed blob \n"
f"Name: {myblob.name}\n"
f"Blob Size: {myblob.length} bytes")
# Add any additional logic you want to perform on the blob's data here
try:
# Read the blob content (assuming it's a text file for this example)
content = myblob.read().decode('utf-8') # Decoding assuming it's UTF-8 text
logging.info(f"Blob content:\n{content}")
# Add any additional processing of the content as needed
# For example, you could upload the content to another storage service or process it
except Exception as e:
logging.error(f"Error processing blob: {str(e)}")
- Ensure the Path of the blob given correctly like below:
Function.json:
{
"scriptFile": "__init__.py",
"bindings": [
{
"name": "myblob",
"type": "blobTrigger",
"direction": "in",
"path": "samples-workitems/hello.ipynb",
"connection": "store21_STORAGE"
}
]
}
local.settings.json:
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "Your-storage conn-string",
"FUNCTIONS_WORKER_RUNTIME": "python",
"store21_STORAGE": "Your-storage conn-string"
}
}
The blob uploaded successfully in respective container like below:
After uploading the blob into container, the status of the function check below:
Output:
本文标签: azure blob trigger is not working when files uploaded in the storage container PythonStack Overflow
版权声明:本文标题:azure blob trigger is not working when files uploaded in the storage container [Python] - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745156425a2645199.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论