@masvio/uploader v2.1.2
MASV Web Uploader
Installation
yarn add @masvio/web-uploader
Usage
Module
import { Uploader } from "@masvio/uploader";
const uploader = new Uploader(
packageID,
packageToken,
apiURL,
);
IIFE (Legacy)
Include the uploader library in your page:
<script type="text/javascript" src="<path-to-uploader>/index.iife.js"></script>
const uploader = new MASV.Uploader(
packageID,
packageToken,
apiURL,
);
API Reference
Constructor
new Uploader(packageID, packageToken, apiURL)
Param | Type | Description |
---|---|---|
packageID | string | the ID of the package for which the files will be uploaded. This can be obtained by creating a portal package or a team package |
packageToken | string | the authorized JWT token for the package, also obtained at time of package creation |
apiURL | string | the base URL of MASV API, which should be https://api.massive.app for production |
Methods
setListener
Add listeners to different events broadcast by the uploader:
uploader.setListener({
onProgress: (completed, total, speed) => {},
onFileComplete: (file) => {},
onRetry: (reason) => {},
onComplete: () => {},
onError: (error) => {},
});
The events and their callback parameters are defined below:
onProgress
Upload progress occurs (bytes getting uploaded). It reports completed bytes so far, and total byte size of all files.
Param | Type | Description |
---|---|---|
completed | number | The number of bytes uploaded so far |
total | number | The total number of bytes to be uploaded |
speed | object | An object representing the current upload speed |
speed.instant | number | instant speed since the last onProgress call |
speed.average | number | the rolling average of upload speed since the beginning of the upload |
speed.moving | number | moving speed is the moving average of upload speed in the last 30 seconds |
Please note that the progress is not necessarily monotonic. As the uploader processes chunks, it reports the progress inclusive of chunks that are in flight. In the event of a retry due to a retriable error, it resets the progress to the previous value prior to uploading the chunk since chunks have to be uploaded entirely. It's up to you to handle this behaviour in the UI.
onFileComplete
One of the supplied files finishes uploading, it indicates which file object was completed
Param | Type | Description |
---|---|---|
file | File | A Javascript File object - like the one returned from <input type="file"> |
onRetry
The uploader retries a request (for example a file chunk upload) due to an error that is deemed retriable by the uploader (for example, a network error or a 5xx server error)
Param | Type | Description |
---|---|---|
reason | Error |
onComplete
The upload is completed and the package have been finalized
onError
An unrecoverable error has occurred and the upload halted (for example, a 401 server error is considered unrecoverable)
Param | Type | Description |
---|---|---|
error | Error |
upload
Upload a collection of MasvFiles
uploader.upload([
{
id,
file,
path,
},
]);
Param | Type | Description |
---|---|---|
files | array | An array of MasvFiles |
MasvFile
Param | Type | Description |
---|---|---|
id | string | An ID for the upload |
file | File | The Javascript File object representing the file on your local system |
path | string | The path of the file to retain folder structure on the other side |
terminate
Cancel your current upload
uploader.terminate();
6 days ago
11 days ago
29 days ago
1 month ago
1 month ago
2 months ago
2 months ago
2 months ago
2 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
3 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
4 months ago
5 months ago
5 months ago
5 months ago
6 months ago
7 months ago
7 months ago