Download file using flask python

Method 1: 

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)

See gist here.

Method 2:

from flask import Flaskfrom flask import send_fileapp = Flask(__name__)@app.route('/download')def downloadFile ():    #For windows you need to use drive name [ex: F:/Example.pdf]    path = "/Examples.pdf"    return send_file(path, as_attachment=True)if __name__ == '__main__':    app.run(port=5000,debug=True) 

See gist here