Question

I am having kind a wired problem with my code. I am uploading file from form, which i get InMemoryUploadedFile.

image_node = data['image_url'] # InMemoryUploadedFile
body = image_node.read()
# do whatever you like with the picture, 

pil_image = Image.open(image_node) # PIL image object. 
# i get error that Cannot identify image. 

When I open PIL first, i works fine, and then image_node.read() fails. I think i am missing some file object concept. Please find the semantic error.

Was it helpful?

Solution

Try this

image_node = data['image_url']
body = image_node.read()

# do stuff

image_node.seek(0)
pil_image = Image.open(image_node)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top