Created
March 7, 2013 02:45
-
-
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
This file contains 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
// 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); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this example also in an async chain, hence the callback on 18