Skip to content

Instantly share code, notes, and snippets.

@andrepadez
Created February 18, 2014 10:16
Show Gist options
  • Save andrepadez/9068119 to your computer and use it in GitHub Desktop.
Save andrepadez/9068119 to your computer and use it in GitHub Desktop.
Node.js File upload to Amazon S3
fs.readFile(file.path, function(err, buff){
completed++;
if(err){ return; }
var headers = {
'Content-Length': buff.length,
'Content-Type': 'text/plain'
};
var push = client.put(file.name, headers);
push.on('response', function(res){
if(res.statusCode === 200){
console.log('saved', Object.keys(push));
uploaded.push(push.url);
if(completed === files.length){
callback(null, uploaded);
}
}
});
push.end(buff);
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment