Python Forum

Full Version: Help with return on REST API Flask
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello
I have manage to create a REST API Server that uplaod a file on reqeust.
my question is simple :
how can I aslo return a message on browser?

soemthing like "download should start now" and also download the file?

I have try this:

@api.route("/test")
def CreateFile():
    StartTime = request.args.get('StartTime')
    print("Start Time is   ", str(StartTime))
    try:
        LogName = FilterLogFile(StartTime)
    except TypeError as e:
        print(e)
        return str(e)
    except ValueError as e:
        print(e)
        return str(e)
    else:
        send_from_directory(UPLOAD_DIRECTORY, "CutLogData1.txt", as_attachment=True)
        return "OK - download start", 200
but he only print me the "OK - download start", 200
and it doesn't download anything
when I put the send_from_directory into the return - the file is downloding

how can i combine the 2? (if it's possiable)

Thanks ,