I am facing a huge problem when I’m uploading an image (.jpg or .png) via the dcc.upload component: I have to feed the image into a function that accepts either a string or PIL.Image object. In my opinion it would be better to convert it to a PIL.Image (?). So I have to convert the base64 encoded image to a PIL.Image object but I cannot get this to work. I am able to display the uploaded image in dash though. Please help!
I tried the following: (uploaded image is called
upload, function for further use called
OSError: [Errno 63] File name too long: 'data:image/png;base64,iVB...
assert isinstance(image, str) or isinstance(image, Image.Image)
ValueError: embedded null byte
OSError: cannot identify image file <_io.BytesIO object at 0x146225d10>
upload = base64.b64decode(upload + '===')didn’t help
ImageFile.LOAD_TRUNCATED_IMAGES = Truedidn’t help
But the image file can’t be corrupted as I can clearly display it in the browser?
And getting a string (or path) out of it is also not a good idea I think as the image will be uploaded from the user?