Skip to content

Instantly share code, notes, and snippets.

@haswalt
Created February 18, 2016 19:53
Show Gist options
  • Save haswalt/5a7725278cc6a5f2830e to your computer and use it in GitHub Desktop.
Save haswalt/5a7725278cc6a5f2830e to your computer and use it in GitHub Desktop.
aws-uploader-simple
;(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