0

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 + '"/>');
});
Justin
  • 2,224
  • 2
  • 22
  • 28

2 Answers2

3

IMDB returns a 403 (Forbidden) HTTP status for that image URL. My guess is that IMDB is blocking the image based on the referrer for the request. This is often used to prevent deep-linking to resources so one web site can't "steal" bandwidth/content from other sites. Even this JSFiddle shows a broken image, but loading the image URL directly in the browser works.

<img src="http://ia.media-imdb.com/images/M/MV5BMTMyMzA5ODIzMV5BMl5BanBnXkFtZTcwNzE2NDM1Mw@@._V1_SY317_CR52,0,214,317_.jpg"/>

The solution would be to not use IMDB images, which they're not making available for public linking.

Jacob
  • 77,566
  • 24
  • 149
  • 228
  • I would upvote this answer, but I need a reputation of 15 or higher! I know this a delayed response, but thanks! – Justin Jan 05 '14 at 00:14
0

Try this:
res.write('<img src="http://ia.media-imdb.com/images/M/MV5BMTMyMzA5ODIzMV5BMl5BanBnXkFtZTcwNzE2NDM1Mw@@._V1_SY317_CR52,0,214,317_.jpg">');

Image tags are self closing. There is no closing tag.

Jamis Charles
  • 5,827
  • 8
  • 32
  • 42