Flask send_file() returning correct .xlsx data but incorrect filename Flask send_file() returning correct .xlsx data but incorrect filename flask flask

Flask send_file() returning correct .xlsx data but incorrect filename


the file is being called download because that's the path you have set.

@app.route('/download', methods=['GET'])def download():

If you don't have the ability to control the users' requests you should be able to define a false filename by using a redirect, otherwise just use the new route for download as defined.

Try something like this?

...from flask import redirect...@app.route('/download', methods=['GET'])def download_redirect():    redirect('/download/test.xlsx')@app.route('/download/<filename>', methods=['GET'])def download(filename):    run_id = request.args.get('run_id')    fp = BucketHelper().get_report_fp(run_id)    send_file(fp,             as_attachment=True,             mimetype='application/vnd.ms-excel',             attachment_filename="test.xlsx")