I am having a very hard time with this. If I had an external image url. For example, this is a picture url from IMDb.com, http://ia.media-imdb.com/images/M/MV5BMTMyMzA5ODIzMV5BMl5BanBnXkFtZTcwNzE2NDM1Mw@@._V1_SY317_CR52,0,214,317_.jpg. How would I be able to send this image to the client?
currently, I'm doing:
res.write('<img src="/http://ia.media-imdb.com/images/M/MV5BMTMyMzA5ODIzMV5BMl5BanBnXkFtZTcwNzE2NDM1Mw@@._V1_SY317_CR52,0,214,317_.jpg"></img>');
But it's not showing, I'm just getting a broken image.
UPDATE:
I ended up doing this to make this work:
var url = http://ia.media-imdb.com/images/M/MV5BMTMyMzA5ODIzMV5BMl5BanBnXkFtZTcwNzE2NDM1Mw@@._V1_SY317_CR52,0,214,317_.jpg;
var loadBase64Image = function (url, callback) {
var request = require('request');
request({url: url, encoding: null}, function (err, res, body) {
if (!err && res.statusCode == 200) {
var base64prefix = 'data:' + res.headers['content-type'] + ';base64,'
, image = body.toString('base64');
if (typeof callback == 'function') {
callback(image, base64prefix);
}
} else {
throw new Error('Can not download image');
}
});
};
loadBase64Image(imageUrl, function (image, prefix) {
res.write('<img src="' + prefix + image + '"/>');
});