Skip to main content
 首页 » 编程设计

python之将图像从 Flask 的 request.files 属性加载到 PIL Image

2024年12月31日7dflying

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

返回:

IOError: cannot identify image file




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

返回:

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



请问这样做的正确方法是什么?

请您参考如下方法:

这可以工作。
img = Image.open(request.files['file'].stream)
也许为时已晚,但希望它能帮助其他人找到这个。