javascript - Cannot save a remote image with node.js and request -


I want to save an image with node.js. So far I have this simple code:

  var request = required ('request'); Var FS = Requirement ('FS'); Request ('http://upload.wikimedia.org/wikipedia/commons/8/8c/JPEG_example_JPG_RIP_025.jpg', function (error, feedback, body) {// more logic determines whether the image will be desired or Not saved fs.writeFile ('downloaded.jpg', body, function () {});})  

But this does not work Image always gets corrupted. I think this is an encoding error but how can I decide.

  var request = required ('request'), FS = requirement ('FS') , URL = 'http://upload.wikimedia.org/wikipedia/commons/8/8c/JPEG_example_JPG_RIP_025.jpg'; Request (url, {encoding: 'binary'}, function (error, feedback, body) {fs.writeFile ('downloaded .jpg', body, 'binary', function (mistake) {});});  

Comments

Popular posts from this blog

HTML/CSS - Automatically set height width from background image? -

php - Mysql Show Process - Sleep Commands and what to do -

c - What is the address of buf (the local variable in the main function)? -