Skip to content

Instantly share code, notes, and snippets.

@patelsan
Last active August 29, 2015 13:58
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 patelsan/9964921 to your computer and use it in GitHub Desktop.
Save patelsan/9964921 to your computer and use it in GitHub Desktop.
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