从Flask's加载图像请求.files属性到PIL Imag

2024-05-16 12:32:41 发布

您现在位置:Python中文网/ 问答频道 /正文

image = Image.open(request.files["fullimage"])

退货:

IOError: cannot identify image file

以及

^{pr2}$

退货:

IOError: [Errno 22] invalid mode ('rb') or filename: ''

请问,正确的方法是什么?在


Tags: imagemoderequestfilesopenfilerbidentify
2条回答

这可能有用。在

img = Image.open(request.files['file'].stream)

也许已经太迟了,但希望它能帮助其他找到这个的人。在

我知道这会发生:在尝试组合一个简单的测试用例时,我发现了问题并解决了它。它失败了,因为在尝试将它加载到图像中之前,我正在做其他事情,包括:

request.files["fullimage"].read()

没有这个,它工作得很好。添加:

^{pr2}$

在这和将它加载到图像中的行之间,解决了这个问题。我的意思是,我现在有另一个问题,但我会分开发表;-)

相关问题 更多 >