Created
February 18, 2014 10:16
-
-
Save andrepadez/9068119 to your computer and use it in GitHub Desktop.
Node.js File upload to Amazon S3
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
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