Last active
August 29, 2015 13:58
-
-
Save patelsan/9964921 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
Writable = require('stream').Writable | |
AWS = require('aws-sdk') | |
S3Uploader = (options = {})-> | |
AWS.config.loadFromPath('./config/s3.json') #ToDo: ideally this should be done only once | |
uploader__ = Writable({objectMode: true}) | |
uploader__.write = (__newFile, encoding, done)-> | |
console.log __newFile.filename | |
s3 = new AWS.S3() | |
params = {Bucket: 'test_bucket/tenant_101/project_1', Key: __newFile.filename, Body: __newFile, ContentLength: __newFile.byteCount} | |
s3.putObject(params, (err, data)-> | |
if(err) | |
console.log err | |
else | |
console.log 'Successfully uploaded the file' | |
console.log data) | |
return uploader__ | |
module.exports = S3Uploader |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment