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

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


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.