Temp files are not created in Azure function

Maryna Paluyanava 191 Reputation points
2024-04-24T15:45:31.1733333+00:00

Hello,

I am trying to create an Azure function that takes input zipped folders from blob container, unzips them and writes files into another folder. When I run the function locally, all files are created in blob storage. However, after deployment these files are not created. Perhaps something should be changed in the Azure function configuration?

Could anybody help me?

Thank you!

import logging
import azure.functions as func
import os
import zipfile
import tempfile
from io import BytesIO
from azure.storage.blob import BlobServiceClient


app = func.FunctionApp()
           
@app.blob_trigger(arg_name="myblob",
                path="files/input/{name}",
                connection="AzureWebJobsStorage")




def main(myblob: func.InputStream) -> None:
    logging.info(f"Python blob trigger function processed blob \n"
                 f"Name: {myblob.name}\n"
                 f"Blob Size: {myblob.length} bytes")
                 
    #connect to storage account
    connect_str = "XXXX"
    output_container = "files"
    blob_service_client = BlobServiceClient.from_connection_string(connect_str)

    output_container_client = blob_service_client.get_container_client(output_container)

    #download blob
    read_zip = myblob.read()
    converted_data = BytesIO(read_zip)

    
    #create zipfile object and upload extracted files
    zip_object = zipfile.ZipFile(converted_data, "a")
    with tempfile.TemporaryDirectory() as dir_name:
        for filename in zip_object.namelist():
            directory = os.path.basename(filename)
            #skip directories
            if not directory:
                continue
            
            zip_object.extract(filename, path=dir_name)
            file_location = os.path.join(dir_name, filename)
            with open(file_location, "rb") as f:
                blob_client_output = output_container_client.get_blob_client(filename)
                blob_client_output.upload_blob(f, overwrite=True)

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,300 questions
{count} votes