在烧瓶中使用PIL映像send_file而不保存到磁盘?

问题描述

我正在将PIL图像保存到io.BytesIO()对象。

imgByteArr = io.BytesIO()
img.save(imgByteArr,format=format)

然后尝试将图像返回给用户

return send_file(img.getvalue(),mimetype="image/" + img_details["ext"].lower())

但是我遇到了错误

TypeError: The view function did not return a valid response. The function either returned None or ended without a return statement.

我不想作为附件发送,我希望图像显示页面上。

有人知道不先保存到磁盘就可以吗?

解决方法

我错过了“寻找”

imgByteArr = io.BytesIO()
img.save(imgByteArr,format=format)
imgByteArr.seek(0)

return send_file(imgByteArr,mimetype="image/" + img_details["ext"].lower())

这现在有效。