Domanda

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.

È stato utile?

Soluzione

Try this

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

# do stuff

image_node.seek(0)
pil_image = Image.open(image_node)
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top