I'm having a Unity function writen in C# to allow users to upload customized images. The image is sent as byte[] in string format.
I have a simple flask backend server to save the images. However, when I worked with io.BytesIO
and Image.open()
functions, it shows cannot identify image file <_io.BytesIO object at 0x7f5599f43308>
Here is my code:
@app.route("/post_file",methods=['GET','POST'])
def post_file():
data = request.form.to_dict()
json_byte = data['jsonbytes'] # posting a json byte[] and image byte[] with multi-form
image_byte = data['imagebytes'] # a byte[] in string type
image_byte = data['imagebytes'].encode() # byte[] type
imageBytesIO=io.BytesIO(image_byte)
imageBytesIO.seek(0)
image = Image.open(imageBytesIO).convert('RGBA')
The code breaks at the last line.
File "/home/iedl/editor/editor_app/app.py", line 37, in post_file
image = Image.open(imageBytesIO).convert('RGBA')
File "/home/iedl/editor/editor_env/lib/python3.5/site-packages/PIL/Image.py", line 2818, in open
raise IOError("cannot identify image file %r" % (filename if filename else fp))
OSError: cannot identify image file <_io.BytesIO object at 0x7f5599f43308>