Skip to content

Instantly share code, notes, and snippets.

@fzaninotto
Created June 17, 2012 20:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fzaninotto/25bd6f592f44db7edb7b to your computer and use it in GitHub Desktop.
Save fzaninotto/25bd6f592f44db7edb7b to your computer and use it in GitHub Desktop.
var fs = require('fs');
var filenames = fs.readdirSync(path);
filenames.forEach(function(filename) {
var postOptions = {
host: 'api.flickr.com',
port: '80',
path: '/services/upload/',
method: 'POST',
headers: {
'Content-Disposition': 'attachment; filename=' + $filename,
'Content-Type': 'application/octet-stream'
}
};
// open an HTTP request to Flickr (returns a stream)
var httpStream = http.request(postOptions, function(res) {
// dispose of the response status and body
});
// open a file stream on the local image
var fileStream = fs.createReadStream(path + filename);
// read from the file and write to the HTTP request
fileStream.pipe(httpStream);
fileStream.on('end', function() {
console.log('Sent file ' + filename);
});
});
console.log('Finished!');
@kiasaki
Copy link

kiasaki commented Aug 13, 2014

Should $filename be written like that or it's a leftover from php? https://gist.github.com/fzaninotto/25bd6f592f44db7edb7b#file-gistfile1-js-L11

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment