Skip to content

Instantly share code, notes, and snippets.

@basiclines
Created October 17, 2017 07:32
Show Gist options
  • Save basiclines/d52623f9ded7e241acbf9e5bbe2808e4 to your computer and use it in GitHub Desktop.
Save basiclines/d52623f9ded7e241acbf9e5bbe2808e4 to your computer and use it in GitHub Desktop.
NodeJS script to download a batch of images one by one
var fs = require('fs'),
request = require('request');
images = require('./images') // Array of images urls
var download = function(uri, filename, callback){
request.head(uri, function(err, res, body){
request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
});
};
var idx = 0;
var getImage = function(image) {
var parts = image.split('/');
var filename = parts[7] + '_' + parts[8] + '.jpg'
idx++
download(image, filename, function done() {
console.log('saved: ', filename)
getImage(images[idx])
})
}
getImage(images[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment