Skip to content

Instantly share code, notes, and snippets.

@hiteshjoshi
Created May 28, 2015 06:47
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hiteshjoshi/5226abcb225038d969de to your computer and use it in GitHub Desktop.
Save hiteshjoshi/5226abcb225038d969de to your computer and use it in GitHub Desktop.
var s3 = require('s3');
//s3 client
var client = s3.createClient({
maxAsyncS3: 20, // this is the default
s3RetryCount: 3, // this is the default
s3RetryDelay: 1000, // this is the default
multipartUploadThreshold: 20971520, // this is the default (20 MB)
multipartUploadSize: 15728640, // this is the default (15 MB)
s3Options: {
accessKeyId: "MY ID",
secretAccessKey: "MY ACCESS KEY",
endpoint : "some.endpoint.com.s3-website-ap-southeast-1.amazonaws.com",
s3BucketEndpoint:true
// any other options are passed to new AWS.S3()
// See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/Config.html#constructor-property
},
});
var assets = {
localDir: "/var/www/html/website/assets",
deleteRemoved: true, // default false, whether to remove s3 objects
// that have no corresponding local file.
s3Params: {
Bucket: "some.endpoint.com",
Prefix: "/images/",
// other options supported by putObject, except Body and ContentLength.
// See: http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html#putObject-property
},
};
var assets_uploader = client.uploadDir(assets);
assets_uploader.on('error', function(err) {
console.error("unable to sync assets folder , error :", err.stack);
});
assets_uploader.on('progress', function(err) {
console.log("Processing the data sync for the direcotry assets ." , assets_uploader.progressMd5Amount,assets_uploader.progressAmount,assets_uploader.progressTotal)
});
assets_uploader.on('end', function(err) {
console.log("Done uploading the direcotry. assets !!!")
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment