Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send image and JSON data in single Node.js + Express response

I am creating a web API with Node.js and Express and intend to use a single response to return an image and JSON data simultaneously. I saw a solution to specify headers: https://stackoverflow.com/a/18864738/1703565 but I do not want to perform two get requests. How do I accomplish this?

like image 832
Royston Yinkore Avatar asked Oct 15 '25 15:10

Royston Yinkore


1 Answers

You could encode the image as a base64 string (http://nodejs.org/api/buffer.html#buffer_buf_tostring_encoding_start_end), and return this as part of your JSON.

like image 179
Kevin Schmid Avatar answered Oct 17 '25 06:10

Kevin Schmid