Flask Send_file Download ((better))_name May 2026
: attachment_filename was renamed to download_name to better reflect its purpose.
Your server-side file has a generic name (e.g., temp_report_123.pdf ) but you want the user to see a friendly name (e.g., Monthly_Financial_Report.pdf ). flask send_file download_name
The download_name parameter specifies the the browser will use when saving the file to the user's local disk. This is particularly useful when: : attachment_filename was renamed to download_name to better
You are generating files dynamically in memory (using io.BytesIO ) and there is no physical file on disk to provide a name. The Evolution: download_name vs. attachment_filename This is particularly useful when: You are generating
from flask import Flask, send_file app = Flask(__name__) @app.route('/get-report') def download_report(): # The actual file path on your server file_path = "storage/data/raw_file_01.pdf" # Send it with a custom name for the user return send_file( file_path, as_attachment=True, download_name="User_Friendly_Report.pdf" ) Use code with caution. Common Use Cases and Tips Changes — Flask Documentation (3.1.x)
: The old name was completely removed, so using attachment_filename in modern Flask versions will result in a TypeError . Basic Implementation