Saving uploaded base64 data gives TypeError: a bytes-like object is required, not 'str'

核能气质少年 提交于 2019-12-02 08:49:56

StringIO represents a string, not bytes, you want BytesIO. Base64 encoded data is not the actual image bytes, it needs to be decoded with b64decode.

file_data = io.BytesIO(b64decode(image_base))

You need to encode either app.config['UPLOAD_FOLDER'] or , filename to be a byte-like object. Try the .encode('utf-8') method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!