Created
February 18, 2016 19:53
-
-
Save haswalt/5a7725278cc6a5f2830e to your computer and use it in GitHub Desktop.
aws-uploader-simple
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
;(function() { | |
'use strict'; | |
function Uploader() { | |
AWS.config.update({ | |
accessKeyId: '', | |
secretAccessKey: '' | |
}); | |
AWS.config.region = 'us-east-1'; | |
this.opts = { | |
bucket: 'cloud.wbpapps.com', | |
partSize: 10 * 1024 * 1024, | |
concurrency: 5, | |
prefix: 'howtobesingle/humblebrag/' | |
}; | |
}; | |
Uploader.prototype.upload = function(file, key, callback, progressCallback) { | |
var params = { | |
Key: this.opts.prefix + key, | |
Bucket: this.opts.bucket, | |
ContentType: file.type, | |
Body: file, | |
ACL: 'public-read' | |
}; | |
var upload = new AWS.S3.ManagedUpload({ | |
partSize: this.opts.partSize, | |
queueSize: this.opts.concurrency, | |
params: params | |
}); | |
if (typeof progressCallback == "function") { | |
upload.on('httpUploadProgress', progressCallback); | |
} | |
if (typeof callback == "function") { | |
upload.send(callback); | |
} else { | |
upload.send(function (err, data) { | |
if (err) _.log("Error:", err.code, err.message); | |
}); | |
} | |
}; | |
this.Uploader = Uploader; | |
}).call(this); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment