-1

I want to save an image from the response body to my local directory.
Here is my code:

return Response(bytes_io.getvalue(), media_type= "image/jpeg")
Nimantha
  • 5,793
  • 5
  • 23
  • 56
  • Any reason why you can't retrieve the bytes (as you're already doing) to a variable, write that content to disk and then deliver the response? – MatsLindh May 13 '22 at 11:19
  • I'm trying to print the return, here the response "" –  May 13 '22 at 11:43
  • You don't need the response; you already have read the data here: `bytes_io.getvalue()`. Assign this to a variable: `image_data = bytes_io.getvalue()`, then write that content to a file as you wish, before `return Response(image_data, ..)` – MatsLindh May 13 '22 at 11:52
  • 1
    Does this answer your question? [Render NumPy array in FastAPI](https://stackoverflow.com/questions/71595635/render-numpy-array-in-fastapi) – Chris May 14 '22 at 10:20
  • Thank you, first answer it's work. But, my connection is lost and my replay is not sent. –  May 14 '22 at 16:59

0 Answers0