2.1.2 • Published 6 days ago

@masvio/uploader v2.1.2

Weekly downloads
-
License
SEE LICENSE IN LI...
Repository
-
Last release
6 days ago

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)
ParamTypeDescription
packageIDstringthe ID of the package for which the files will be uploaded. This can be obtained by creating a portal package or a team package
packageTokenstringthe authorized JWT token for the package, also obtained at time of package creation
apiURLstringthe 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.

ParamTypeDescription
completednumberThe number of bytes uploaded so far
totalnumberThe total number of bytes to be uploaded
speedobjectAn object representing the current upload speed
speed.instantnumberinstant speed since the last onProgress call
speed.averagenumberthe rolling average of upload speed since the beginning of the upload
speed.movingnumbermoving 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

ParamTypeDescription
fileFileA 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)

ParamTypeDescription
reasonError

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)

ParamTypeDescription
errorError

upload

Upload a collection of MasvFiles

uploader.upload([
    {
        id,
        file,
        path,
    },
]);
ParamTypeDescription
filesarrayAn array of MasvFiles

MasvFile

ParamTypeDescription
idstringAn ID for the upload
fileFileThe Javascript File object representing the file on your local system
pathstringThe path of the file to retain folder structure on the other side

terminate

Cancel your current upload

uploader.terminate();
2.1.3-beta.1

6 days ago

2.1.2

11 days ago

2.1.0

29 days ago

2.0.5-beta.2

1 month ago

2.0.5-beta.1

1 month ago

2.0.4

2 months ago

2.0.4-beta.3

2 months ago

2.0.4-beta.1

2 months ago

2.0.4-beta.2

2 months ago

2.0.3

3 months ago

2.0.2

3 months ago

2.0.1-beta.1

3 months ago

2.0.1

3 months ago

2.0.0

3 months ago

2.0.0-beta.18

3 months ago

2.0.0-beta.17

3 months ago

2.0.0-beta.16

3 months ago

2.0.0-beta.15

4 months ago

2.0.0-beta.14

4 months ago

2.0.0-beta.13

4 months ago

2.0.0-beta.11

4 months ago

2.0.0-beta.12

4 months ago

2.0.0-beta.10

4 months ago

2.0.0-beta.9

4 months ago

2.0.0-beta.8

4 months ago

2.0.0-beta.7

4 months ago

2.0.0-beta.6

4 months ago

2.0.0-beta.5

4 months ago

2.0.0-beta.4

5 months ago

2.0.0-beta.3

5 months ago

2.0.0-beta.2

5 months ago

2.0.0-beta.1

6 months ago

1.1.1

7 months ago

1.1.0

7 months ago