I'm trying to read an image that the user uploads and then display the image back to them. I want to do this without saving the image file that is uploaded.
I have code like this:
from flask import Flask, redirect, render_template, request, url_for, send_file
from PIL import Image, ImageDraw
from io import BytesIO
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
img = Image.open(request.files['file'].stream)
byte_io = BytesIO()
img.save(byte_io, 'PNG')
byte_io.seek(0)
return send_file(byte_io, mimetype='image/png')
if __name__ == '__main__':
app.run(debug=1)
It produces this error:
TypeError: send_file() got an unexpected keyword argument 'mimetype'
I've tried replacing mimetype with other valid parameters and it will just give the same error but with the name of the new parameter. So I think the problem is with my bytes_io.
UPDATE:
To clarify, by send_file() I'm referring to the built in flask.send_file() method:
send_file()? didn't get you