In Python Azure Functions, binding expressions like {filename}
in the path
work differently compared to C#. The binding expressions can be used, but they are not automatically available as function parameters (unlike in C#). You can use {filename}
in the path
of your blob trigger binding. However, you cannot add filename
as a separate parameter to the function. Instead, you should access it from the myblob.name
property and parse it manually.
Try the following:
import azure.functions as func
import logging
import os
app = func.FunctionApp()
@app.blob_trigger(arg_name="myblob", path="%code_env%/src/{filename}.txt",
connection="storagetriggerfunc_STORAGE")
def blob_trigger(myblob: func.InputStream):
# Full blob name (path + filename)
blob_name = myblob.name # e.g., "container/src/foo.txt"
# Extract filename from the blob name
filename = os.path.basename(blob_name) # "foo.txt"
logging.info(f"Python blob trigger processed blob")
logging.info(f"Name: {filename}")
logging.info(f"Blob Size: {myblob.length} bytes")
-
myblob.name
: gives you the full path to the blob (including container name). -
os.path.basename(...)
: extracts just the{filename}.txt
part from the path.
The following is invalid because Python Azure Functions does not support direct binding of path parameters to function arguments like C# does.
def blob_trigger(myblob: func.InputStream, filename: str):
If the above response helps answer your question, remember to "Accept Answer" so that others in the community facing similar issues can easily find the solution. Your contribution is highly appreciated.
hth
Marcin