I have a toy react app that asks a toy nodejs server to do some image processing and return the result. The image processing server does this:
let result = path.join(__dirname, '/../../tmp/', name)
// .. write image to result
res.status(200).sendFile(result)
Logging this response on the client, I get:
{ data: "...binary image stuff...", status: 200, etc }
(1) How do I get that image data in data
into an <img>
tag in JSX? src={response.data}
? that doesn't work
(2) Am I going about this wrong? Is the better way to just answer the filename in tmp then have the img src refer to that path? This idea seems better, except I'll get no chance to clean up the tmp file because I won't know when the img tag has finished getting it.
If there's a better way than (1) or (2) (like maybe a stream?) that would be great to understand, too. Thanks.