Skip to content
Advertisement

Return Excel file in Flask app

I am creating a Flask application that prompts the user for an Excel file, does some work with it, then returns the file back to the user so that they can download it. (Please ignore any unused imports. I plan on using them later on.)

I have my functionality down, i’m just not sure how to send the file back to the user so that they can download it. Thanks in advance for any help!

Here’s what I have so far: (note: i’m not too sure if I implemented the upload function properly)

JavaScript

Advertisement

Answer

It depends if you want to keep the file on your server/computer or not. You could do something like this to keep the files:

JavaScript

And if you don’t want to keep the files, this snippet can help you.

Note: As per Flask 1.1.1, send_from_directory() syntax has been updated. You might need to include directory too.

https://flask.palletsprojects.com/en/1.1.x/api/#flask.send_from_directory

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement