How to set a custom file name for an Azure output blob binding with Python v2 programming model?

Florence 0 Reputation points


I have a python v2 azure function with an azure storage blob output binding like below. What I want is to take the file name of the input blob, append some naming and then use it as filename for my output blob.

How can I do that?

See my function here:

@app.blob_trigger(arg_name="inputblob", path="input/{filename}", connection="AzureWebJobsStorage")
@app.blob_output(arg_name="outputblob", path="output/outputfile_{Datetime}.xlsx",                 connection="AzureWebJobsStorage")
def main(inputblob: func.InputStream, outputblob: func.Out[str]) -> None:
# do something, generate excel
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,237 questions
Azure Blob Storage
Azure Blob Storage
An Azure service that stores unstructured data in the cloud as blobs.
2,425 questions
{count} votes

1 answer

Sort by: Most helpful
  1. MuthuKumaranMurugaachari-MSFT 22,141 Reputation points

    Florence Thanks for posting your question in Microsoft Q&A. Yes, you can save a custom file name by appending the input filename {filename} (prefix or suffix) in the output file name like below:

    @app.blob_trigger(arg_name="myblob", path="testtrigger/{filename}",
    @app.blob_output(arg_name="outputblob", path="output/out1-{filename}",
    def blob_trigger(myblob: func.InputStream, outputblob: func.Out[str]) -> None:"Python blob trigger function processed blob"
                    f"Name: {}"
                    f"Blob Size: {myblob.length} bytes")
        outputblob.set("test values") //test purpose

    I have tested the above code snippet in my python function and worked as expected. However, you cannot use a binding expression that is not defined in the trigger as metadata/properties in the output (unless another binding expression types such as Trigger file name, JSON payloads etc.). Check out Trigger file name doc which also has an example to use binding expressions/patterns that you can apply and refer to each trigger doc about properties and metadata.

    I hope this helps and let me know if any questions or face any issues.

    1 person found this answer helpful.