Skip to content

Instantly share code, notes, and snippets.

@hiphamster
Forked from Miserlou/flask_binary.py
Created August 30, 2019 05:41
Show Gist options
  • Save hiphamster/76dd1fe66c90034867bf68935d26552e to your computer and use it in GitHub Desktop.
Save hiphamster/76dd1fe66c90034867bf68935d26552e to your computer and use it in GitHub Desktop.
Flask serving binary data example
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