Skip to content

Instantly share code, notes, and snippets.

@philfreo
Created August 22, 2014 21:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save philfreo/b307afd2339767481426 to your computer and use it in GitHub Desktop.
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
@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)
@mikesneider
Copy link

very useful, thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment