Reputation: 711
I have a werd problem. When i am running this code to get a image, but some images make this line quit my program. I dont get any error and i dont know how to debug the problem.
http.get(obj.image.url.split("?")[0], function (getResponse){
var chunks = [];
getResponse.on('data', function (chunk){
chunks.push(chunk);
}).on('end', function(){
if(getResponse.statusCode == 200){
var buffer = Buffer.concat(chunks);
obj.image = {
url: obj.image.url,
width: sizeOf(buffer).width,
height: sizeOf(buffer).height
}
callback(obj);
}
});
});
I try to put a console.log in every step in that function, but nothing i triggering after http.get...
http://static.feber.se/article_images/38/68/15/386815_1280.jpg - WORKS https://tctechcrunch2011.files.wordpress.com/2015/02/crunchweek-4-3.jpg - FAIL
Upvotes: 0
Views: 57
Reputation: 2352
It's because you have to deal with for the different protocols http://
and https://
. It seems there's nothing built-in for node.js
. You may use modules like request or needle instead. They will figure out which protocol to use, and how to handle redirects (if required) and such.
Upvotes: 1
Reputation: 193
The image that's failing is from an HTTPS link. If you are connecting to HTTPS you should use the proper NodeJS class. Its useage is very similar. Checkout the documentation for more info: https://nodejs.org/api/https.html#https_https_get_options_callback
Upvotes: 1