2

I'm writing a web portal in Flask for downloading files from a server. I'm currently trying to use Flask's send_file() command. When I build the site and click' download', the Python download function Python server-side is running and no error messages are returned, I'm never prompted to save a file. I'm working in Windows 10 under Python 3.

I've attempted to use send_from_directory(), but it acts the same way - no errors are thrown, but I am never prompted to download a file.

@app.route('/download_file', methods = ['POST'])
def background_process_test():
    data = request.data.decode("utf-8")[1:-1]
    path = "C:/Users/ehill/OneDrive - LeTourneau University/Code/Python/call-portal/call-portal/"
    print (path + data)
    return send_file(path + data, as_attachment=True, attachment_filename=data)

From the console, I'm receiving as expected:

C:/Users/ehill/OneDrive - LeTourneau University/Code/Python/call-portal/call-portal/Call03.wav
127.0.0.1 - - [04/Jan/2019 15:58:52] "POST /download_file HTTP/1.1" 200 -

But this is all that happens. The path is valid and works when dropped into Windows Explorer. As a note, my browser window doesn't open a new tab or refresh.

Thank you for your feedback.

3
  • 1
    I am not sure about the forward slashes in your path, but aren't you missing the GET method in your app route? Commented Jan 4, 2019 at 23:39
  • I'm not manually making any GET requests that I'm aware of. The POST request was just to get the selected filename from the frontend. In theory, it could be removed and replaced with a hard-coded location for testing, but it appeared to be functioning fine. Commented Jan 7, 2019 at 17:02
  • 1
    As far as I know, if you do not specify the method, it defaults to GET. As I used a function for downloading files with flask, I used GET and POST method, hence my suggestion to test with GET and POST ( or only GET). Not sure if it helps but testing can't do no harm Commented Jan 7, 2019 at 17:26

1 Answer 1

1

Turn on dev tools in Chrome ( ctr-shift-I ). For me this problem was caused by a "mixed content" error that was only visible in the dev tools of the browser. And the source of that error was that while trouble shooting a different problem I had changed the azure web service TLS/SSL settings to be "HTTPS only = ON". After flipping the setting back my calls to send_file() all started behaving normally.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.