Provide multi part upload functionality to Amazon S3 using the knox library
Installation is done via NPM, by running
npm install knox-mpu
To upload a stream, simply pass the stream when constructing the MultiPartUpload. The upload will then listen to the stream, and create parts from incoming data stream. When a part reaches the minimum part size, it will attempt to upload it to S3.
// Create a Knox client firstvar client = knoxcreateClientupload = null;upload =client: clientobjectName: 'destination.txt' // Amazon S3 object namestream: stream// Callback handler// If successful, will return a JSON object containing Location, Bucket, Key and ETag of the object;
To upload a file, pass the path to the file in the constructor. Knox-mpu will split the file into parts and upload them.
// Create a Knox client firstvar client = knoxcreateClientupload = null;upload =client: clientobjectName: 'destination.txt' // Amazon S3 object namefile: // path to the file// Callback handler// If successful, will return a JSON object containing Location, Bucket, Key and ETag of the object;
The following options can be passed to the MultiPartUpload constructor -
clientRequired The knox client to use for this upload request
objectNameRequired The destination object name/path on S3 for this upload
streamThe stream to upload (required if file is not being supplied)
fileThe path to the file (required if stream is not being supplied)
headersAny additional headers to include on the requests
partSizeThe minimum size of the parts to upload (default to 5MB).
The MultiPartUpload will emit a number of events -
initiatedEmitted when the multi part upload has been initiated, and received an upload ID. Passes the upload id through as the first argument to the event
uploadingEmitted each time a part starts uploading. The part id is passed as the first argument.
uploadedEmitted each time a part finishes uploading. Passes through an object containing the part id and Amazon ETag for the uploaded part.
errorEmitted each time a part upload fails. Passes an object containing the part id and error message
completedEmitted when the upload has completed successfully. Contains the object information from Amazon S3 (location, bucket, key and ETag)