Next.js Discord

Discord Forum

Image Response on Route Handler

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
I am trying to create a route handler that will fetch an image response from a python rest api server. How do I handle the response in the route handler and how do I directly use the route handler as a source for the Image component from next/image?

Is there a way to make this work? The python server is returning a FastAPI Response of
*main.py

return Response(content=image_bytes, media="image/jpg")


*image.tsx

return (
  <Image src={"/api/image/1"}
)


*api/image/[id]

export async function GET(params){
  const result = await fetch(`backendip/image/${id}`)
  return result.json()
}

0 Replies