I'm using the request and node-canvas modules to try and download and process an image:
var request = require('request');
var Image = require('canvas').Image;
var url = 'http://farm8.staticflickr.com/7333/11286633486_070f0d33bc_n.jpg';
request.get({ url: url, encoding: null }, function(err, res, body) {
if (err) throw err;
var image = new Image();
image.onerror = function() {
console.error(arguments);
};
image.onload = function() {
console.log('loaded image');
};
image.src = new Buffer(body, 'binary');
});
I get the error 'Error: error while reading from input stream
' (the onerror event is fired). But when I hit the above image URL in a browser, it displays the image as expected.
What am I doing wrong?