Skip to content
/ JSss Public

nodejs module to Amazon S3 multipart uploads.

License

Notifications You must be signed in to change notification settings

TotenDev/JSss

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

70 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSss

Nodejs Amazon S3 Multipart upload module

NPM

Dependency Status

Requirements

Installation

Download and install dependencies

$ npm install

Usage

var MultiPart = require("./src/JSss.js")("ohByBucket","MyAccessKey","mySecret","folde/theFileName.zip");
//Register for end event
MultiPart.on("jsss-end",function () {
	console.log("end");	
});
//Register for error event
MultiPart.on("jsss-error",function (err) {
	console.log(err);
});
//Upload finished
MultiPart.on("jsss-upload-notice",function (partNumber,status,err) {
	if (status) {
		partFinished++;
		if (partFinished == partCount) {
			MultiPart.finishUpload();
		}
	}
	else {
		console.log("Upload finished with error:" + err);
		MultiPart.abortUpload();
	}
});
//Must be registered to MultiPart API start
MultiPart.on("jsss-ready",function () {
	console.log("ready");

	partFinished = 0;
	partCount = 2;
	//All datas need to be 5MB>
	MultiPart.uploadChunk("the big data",1);
	MultiPart.uploadChunk("the big data2",2);
});

More samples at samples/ directory.

Methods

Initialize Wrapper

Parameters:

  • bucketID - **Type:**string - **Description:**Name of Object in S3 bucket - REQUIRED
  • AWSAccessKeyID - **Type:**string - **Description:**AWS AccessKeyID - REQUIRED
  • AWSSecretAccessKey - **Type:**string - **Description:**AWS SecretAccessKey - REQUIRED
  • fileName - **Type:**string - **Description:**fileName to be on S3 - REQUIRED
  • options - **Type:**OptionObject - **Description:**Options Object - OPTIONAL
  • options.endPoint - **Type:**string - **Description:**End point to be used - Default is s3.amazonaws.com - OPTIONAL
  • options.useSSL - **Type:**boolean - **Description:**Use SSL or not - Default is true - OPTIONAL
  • options.dataIntegrityEnabled - **Type:**boolean - **Description:**Generates MD5 hash of uploading data for S3 integrity check - Default is true - OPTIONAL
  • options.rrsEnabled - **Type:**boolean - **Description:**Reduced redundancy storage enables customers to reduce their costs by storing non-critical, reproducible data at lower levels of redundancy than Amazon S3's standard storage. - Default is false (Higher level of redundancy) - OPTIONAL

Sample:

var MultiPart = require("./src/JSss.js")("myBucket","AWSAccessKey","AWSSecretAccessKey","fileNameToBeUp",{ endPoint:"secondary.s3.com",useSSL:false,dataIntegrityEnabled:false });

Upload Chunk

Notice this function will not call error listener, it will call upload-notice listener with positionChuck parameter and if succeeded or not, so you can try to re-upload that part if you want.

Parameters:

  • chunkData - **Type:**string || Buffer - **Description:**Chunk to be uploaded - REQUIRED
  • chunkPosition - **Type:**number - **Description:**Chunk Position, so you can upload multiple parts at same time - REQUIRED
  • fileEncoding - **Type:**number - **Description:**Which encoding to use when uploading. Default is utf8 - OPTIONAL

Sample:

MultiPart.uploadChunk(chunkData,chunkPosition,'binary');

Finish Upload

This method will finish upload, and can take a bit long for large files, since amazon will only answer the request when all parts are together.

Sample:

MultiPart.finishUpload();

Finish Upload

This method will cancel upload and delete all uploaded chunks.

Sample:

MultiPart.abortUpload();

Events

####Ready This event MUST be registered in order to wrapper start. When this event is reached you are able to start uploading chunks.

Event-String: jsss-ready

Sample:

//Must be registered to MultiPart API start
MultiPart.on("jsss-ready",function () {
	console.log("I'm ready :)");
}

####Upload Notice This event will be reached when an upload succeeded or failed.

Event-String: jsss-upload-notice

Sample:

MultiPart.on("jsss-upload-notice",function (partNumber,status,err) {
    if (status) {
       console.log("success :) on part:" + partNumber + " with etag:" + err);
    }else {
	   console.log("error:" + err + " on part:" + partNumber + "let's try again?");
    }
});

####Error This event will be reached when an error occur in any fundamental part of upload (start,finish,abort). Do NOT call terminate or abort method from error event, since those methods can emit an error event.

Event-String: jsss-error

Sample:

MultiPart.on("jsss-error",function (err) {
	console.log("Bad",err);
}

####End This event will be reached when upload finished by abortUpload() or finishUpload() OR if it didn't start properly.

Event-String: jsss-end

Sample:

MultiPart.on("jsss-end",function () {
	console.log("Bye");
}

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Added some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

License

MIT

About

nodejs module to Amazon S3 multipart uploads.

Resources

License

Stars

Watchers

Forks

Packages

No packages published