Skip to content

Instantly share code, notes, and snippets.

@tleen
Created March 7, 2013 02:45
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 tleen/5105182 to your computer and use it in GitHub Desktop.
Save tleen/5105182 to your computer and use it in GitHub Desktop.
Node: Recurse through a directory and upload files to s3, using async, knox, underscore
// recurse through tempdir and upload all files
(function uploadFile(filepath, callback){
fs.stat(filepath, function(err, stats){
if(err) return callback(err);
else{
if(stats.isDirectory()){
fs.readdir(filepath, function(err, files){
var files = _.map(files, function(file){ return path.join(filepath, file) });
async.each(files, uploadFile, callback);
});
}else{
var destination = filepath.replace(basePath,'');
if(destination[0] !== '/') destination = ('/' + destination);
client.putFile(filepath, destination, callback);
}
}
});
})(basePath, callback);
@tleen
Copy link
Author

tleen commented Mar 7, 2013

In this example also in an async chain, hence the callback on 18

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