azure blob trigger is not working when files uploaded in the storage container [Python] - Stack Overflow

I'm trying to implement azure blob trigger in python. So whenever a file gets uploaded, blob trigg

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
Add a comment  | 

1 Answer 1

Reset to default -1

azure 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:

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745156425a4614148.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信