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

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -