Hello all
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 function
)
- Using
upload
object itself:OSError: [Errno 63] File name too long: 'data:image/png;base64,iVB...
-
function(base64.b64decode(upload, 'rb'))
:assert isinstance(image, str) or isinstance(image, Image.Image)
-
function(Image.open(base64.b64decode(upload, 'rb')))
:ValueError: embedded null byte
-
function(Image.open(BytesIO(base64.b64decode(upload, 'rb'))))
:OSError: cannot identify image file <_io.BytesIO object at 0x146225d10>
- Using
upload = base64.b64decode(upload + '===')
didn’t help - Using
ImageFile.LOAD_TRUNCATED_IMAGES = True
didn’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?
Thanks!
2 posts - 2 participants