我的代码遇到了问题。
我从表单上传文件,我得到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.
当我首先打开PIL时,我工作正常,然后image_node.read()
失败。我想我错过了一些文件对象的概念。请找到语义错误。
答案 0 :(得分:3)
试试这个
image_node = data['image_url']
body = image_node.read()
# do stuff
image_node.seek(0)
pil_image = Image.open(image_node)