Skip to main content

Chunked Upload

default export chunkedUpload handles a file's data in chunks of a passed in size (default 32MB)

named exports chunkedUploadBase64 handles a file's data in base64 encoded chunks of a passed in size (default 32MB)

##usage

import chunkedUpload from '@rexlabs/chunked-upload';

const file = new File(['abcdefg'], 'filename');
const uploadId = 1;

function uploadChunk(chunkNumber, chunk) {
api.post(`/multipart-uploads/${uploadId}/${chunkNumber}`, {
body: JSON.stringify({ chunk })
});
}

// will read file and call uploadChunk on each 1byte chunk
chunkedUpload(file, uploadChunk, 1).then(() => console.log('Upload complete.'));

// will read file and call uploadChunk on each 1byte base64 encoded chunk
chunkedUploadBase64(file, uploadChunk, 1, false).then(() =>
console.log('base64 upload complete.')
);

// will read file and call uploadChunk on each 32byte chunk, starting at the 15th chunk
chunkedUpload(file, uploadChunk, 32, 15).then(() =>
console.log('Upload complete.')
);

Development

Install dependencies

$ yarn

Available Commands

$ yarn test               # runs all units tests
$ yarn test:watch # runs unit tests when files change
$ yarn build # bundles the package for production

Copyright (c) 2019 Rex Software All Rights Reserved.