I'm trying to download and serve an image with Node.js, but when I get the image it ends with a plus sign:
[data]...9QAPvv70AXFAh2KLvv70/77+977+9
When I embed the data into an HTML image using data:image/jpg;base64, it displays a question mark (invalid image). I'm using this code:
request(image_url, function (error, response, body) {
if (!error && response.statusCode == 200) {
var data_uri_prefix = 'data:' + response.headers['content-type'] + ';base64,';
var image = new Buffer(body).toString('base64');
// To ease testing for now
console.log(image);
}
});
I've tried including the 'binary' parameter when creating the Buffer, among other things. Additionally, the headers don't display any type of special encoding. I'm not really sure why the image is invalid. Is there something I'm missing in the process?