[Python] Sending multiple file uploads as input to Azure function app http trigger

Discussão em 'Python' iniciado por Stack, Janeiro 21, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to send multiple file uploads to a function app (http trigger). The http trigger code is below,

    app = func.FunctionApp(http_auth_level=func.AuthLevel.ADMIN)
    @app.route(route="test_http_trigger", auth_level=func.AuthLevel.ADMIN)
    def test_http_trigger(req: func.HttpRequest) -> func.HttpResponse:
    try:
    if list(req.files.values())[0].filename.split('.')[-1] == 'zip':
    logging.info(req.files.values())
    return func.HttpResponse(str(req.files.values()), mimetype="text/html")
    elif list(req.files.values())[0].filename.split('.')[-1] == 'txt':
    logging.info(req.files.values())
    return func.HttpResponse(str(req.files.values()), status_code=200, mimetype="application/json")
    else:
    return func.HttpResponse('0')
    except Exception as e:
    return func.HttpResponse(f"Internal server error: {e}", status_code=500)


    I tried to send multiple files as input using the curl command below,

    curl -X POST http://localhost:7071/api/test_http_trigger -F "file=@file1.txt" -F "file=@file2.txt"


    This only processes the first file sent. I would like to know the right way to send multiple files to function app.

    Thanks,

    Continue reading...

Compartilhe esta Página