When I work on a Python Flask project, I need to put an .jpg image into a response, however, after I use cv2 read the jpg image, I put the image information into response by make_response. I get the error: "TypeError: The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a ndarray." Is there anything wrong with the read method or encode method of jpg file? Thanks.
@image_proxy_home.route('/images/<int:pid>.jpg')
def get_image(pid):
img = cv2.imread('/user/'+str(pid)+'.jpg')
response = make_response(img)
response.headers.set('Content-Type', 'image/jpeg')
response.headers.set(
'Content-Disposition', 'attachment', filename='%s.jpg' % pid)
return response