Issue
I load an image with img = imageio.imread('hello.jpg')
.
I want to return this numpy array as an image. I know I can do return FileResponse('hello.jpg')
, however, in the future, I will have the pictures as numpy arrays.
How can I return the numpy array img
from FastAPI server in a way that it is equivalent to return FileResponse('hello.jpg')
?
Solution
You can use StreamingResponse (https://fastapi.tiangolo.com/advanced/custom-response/#using-streamingresponse-with-file-like-objects) to do it e.g., but before you will need to convert your numpy array to the io.BytesIO
or io.StringIO
Answered By - dukkee
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.