0

I have an Azure Function as below:

import azure.functions as func
import logging
import os
import tempfile
import subprocess
import json
from pathlib import Path
import glob  

app = func.FunctionApp()


@app.blob_trigger(
    arg_name="myblob",
    path="cssinputbuckettest/{name}.MF4",
    connection="cssdatalakestoragegen2_STORAGE",
)
def BlobTrigger1(myblob: func.InputStream):
    logging.info(
        f"Python blob trigger function processed blob "
        f"Name: {myblob.name} "
        f"Blob Size: {myblob.length} bytes"
    )
...

I can publish my function without issues.

However, in my script I need to use BlobServiceClient, BlobClient to download other files than the trigger blob. Therefore I add the statement below after the other import statements:

from azure.storage.blob import BlobServiceClient, BlobClient

When doing this, however, my publish fails and no function is pushed. Should I download other blobs into my Function in a different way?

2
  • You want to trigger the blobtrigger using the downloaded file using Blobserviveclient, when when downloaded is uploaded to blob container it wikll trigger blob trigger? Commented Apr 27, 2024 at 3:26
  • 1
    My function is triggered when a specific file type is uploaded, MF4 log files. Upon upload, I need to also download another supporting file from my container, a JSON file. In order to do so I am looking to use the blobclient as outlined, but that seems not possible. Commented Apr 27, 2024 at 7:41

1 Answer 1

0

In Python Function, Make sure your code syntax is correct and make sure you are using correct packages.

This worked for me.

I am uploading a *.txt file and downloading download.json file will is available in blob container.

function_app.py

import azure.functions as func
import logging
from azure.storage.blob import *
import os

app= func.FunctionApp()

@app.blob_trigger(arg_name="myblob", path="download/{name}.txt",
                               connection="Storage_conn") 
def BlobTrigger(myblob: func.InputStream):
    logging.info(f"Python blob trigger function processed blob"
                f"Name: {myblob.name}")
    
    client = BlobServiceClient.from_connection_string(os.getenv("Storage_conn"))
    container_client = client.get_container_client("download")
    blob_client = container_client.get_blob_client("download.json")

    downloaded = blob_client.download_blob()

    content = downloaded.readall()

    logging.info(f"Contant of the file: {content}")

OUTPUT

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.