User upload a image file by the Form, I don't want to save original uploaded image file to disk, and resize image by Pillow opening image from disk.
I want to resize this image file in memory first, then save the resized image file to disk. so I import StringIO as buffer, but it does't work with Pillow.
Here is the code:
Python3.4, Flask==0.10.1, Pillow==3.4.2
forms.py
class Form():
img = FileField()
submit = SubmitField()
views.py
from io import StringIO
from PIL import Image
from .forms import Form
@app.route('/upload_img', methods=['GET', 'POST'])
def upload_img():
form = Form()
im = Image.open(StringIO(form.img.data.read())
pass
TypeError: initial_value must be str or None, not bytes