-
-
Save hiphamster/76dd1fe66c90034867bf68935d26552e to your computer and use it in GitHub Desktop.
Flask serving binary data example
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
import io | |
from flask import Flask, send_file | |
app = Flask(__name__) | |
@app.route('/logo.jpg') | |
def logo(): | |
"""Serves the logo image.""" | |
with open("logo.jpg", 'rb') as bites: | |
return send_file( | |
io.BytesIO(bites.read()), | |
attachment_filename='logo.jpeg', | |
mimetype='image/jpg' | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment