Created
August 22, 2014 21:56
-
-
Save philfreo/b307afd2339767481426 to your computer and use it in GitHub Desktop.
How to have Flask download a file and then serve it as an attachment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@app.route('/download/', methods=['GET']) | |
def download(): | |
url = request.args['url'] | |
filename = request.args.get('filename', 'image.png') | |
r = requests.get(url) | |
strIO = StringIO.StringIO(r.content) | |
return send_file(strIO, as_attachment=True, attachment_filename=filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
very useful, thank you!