Created
December 10, 2014 03:11
-
-
Save shiffman/e7fb25220cbefc1acec1 to your computer and use it in GitHub Desktop.
Download an image from flickr with Node
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var fs = require('fs'); | |
| var request = require('request'); | |
| var url = 'https://farm8.staticflickr.com/7484/15685407577_d19030d469_m.jpg'; | |
| var saveFile = 'test.jpg'; | |
| request.head(url, getImage); | |
| function getImage(err, res, body) { | |
| var req = request(url); | |
| var pipe = req.pipe(fs.createWriteStream(saveFile)); | |
| pipe.on('close', finished); | |
| } | |
| function finished() { | |
| console.log('downloaded: ' + url + ' and saved as ' + saveFile); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment