Unable to Download file using flask with actual name
The "options" of send_from_directory
are the same as sendfile
:
flask.send_file(filename_or_fp, mimetype=None, as_attachment=False, attachment_filename=None, add_etags=True, cache_timeout=None, conditional=False, last_modified=None)
So you should call it with:
@app.route('/Download')def Down(): rpm = request.args.get('rpm') root = '/home/rpmbuild/RPMS/' return send_from_directory(root,rpm,attachment_filename='foo.ext')
Where you of course substitute 'foo.ext'
by the name you want to give the file. You probably also want to set the as_attachment
parameter to True
.
In case you want the same name, you can use os.path.basename(..)
for that:
import os@app.route('/Download')def Down(): rpm = request.args.get('rpm') root = '/home/rpmbuild/RPMS/' return send_from_directory(root,rpm,as_attachment=True, attachment_filename=os.path.basename(rpm))