[Vuejs]-$�a �$I��"I�$�… for PNG image – Vue/Node/Express | How do I display an image that I sent from a Node.js server to a client Vue app?

0👍

One approach would be to send the image data as a base64 endcoded string using btoa, the set the image’s src attribute using the encoded string from the response:

<img src=`data:image/png;base64,${data}`/>

Otherwise, you can also return the response image from Express like:

let image = new Buffer(imageData, 'base64');

res.writeHead(200, {
  'Content-Type': 'image/png',
  'Content-Length': image.length
});
res.end(image); 

Leave a comment