问题描述
我正在将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())
这现在有效。