Python Forum
Help with return on REST API Flask
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Help with return on REST API Flask
#1
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 ,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  API REST Package for Calling/Flask muzikman 12 4,235 Oct-22-2021, 07:51 PM
Last Post: muzikman
  rest api parameter in flask bluefrog 3 3,283 Jun-21-2018, 05:03 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020