python - Unable to Download file using flask with actual name -
i trying download file using flask. code follows
@app.route('/download') def down(): rpm = request.args.get('rpm') root = '/home/rpmbuild/rpms/' return send_from_directory(root,rpm)
the name of file passed in url. when hit url, able download file name of file in download
. need actual name of file. have tried send_file()
downloading name download
.
the "options" of send_from_directory
same 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 should call 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 of course substitute 'foo.ext'
name want give file. want set as_attachment
parameter true
.
in case want same name, can use os.path.basename(..)
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))
Comments
Post a Comment