Created
February 13, 2024 02:11
-
-
Save mseeks/8746fd697ce518823c17b6da83e4de35 to your computer and use it in GitHub Desktop.
Python Flask snippet for serving a file at an endpoint. This snippet demonstrates how to use the `send_file` method to allow users to download a file when they access a specific route.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, send_file | |
app = Flask(__name__) | |
@app.route('/download-file') | |
def download_file(): | |
# Path to the file you want to serve up | |
path_to_file = 'path/to/your/file.extension' | |
# Serve the file for download | |
return send_file(path_to_file, as_attachment=True) | |
if __name__ == '__main__': | |
app.run(debug=True) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment