Skip to content

Web Uploader API Reference

This page documents the full API surface of the MASV Web Uploader SDK (@masvio/uploader). For a guided walkthrough, see the Getting Started guide.

import { Uploader } from "@masvio/uploader";
const uploader = new Uploader(packageID, packageToken, apiURL);
ParameterTypeDescription
packageIDstringThe ID of the Package to upload files to. Obtained when creating a Portal Package or a Team Package via the Packages API.
packageTokenstringThe authorized JWT token for the Package, returned at Package creation time.
apiURLstringThe base URL of the MASV API. Use https://api.massive.app for production.

Adds one or more files to the upload queue. Uploading begins automatically once the first file is processed.

uploader.addFiles(file1, file2, ...fileN);

You can also spread an array:

const files = [
{ id: "file-0", file: fileObj, path: "" },
{ id: "file-1", file: fileObj2, path: "subfolder/" },
];
uploader.addFiles(...files);

Each argument must be a MasvFile object.

Resumes the upload after it has been paused. Only required if the uploader was previously paused with pause().

uploader.start();

Pauses the upload. In-flight chunk requests are aborted. Call start() to resume.

uploader.pause();

Cancels the upload. Stops all in-flight transfers and prevents further uploads.

uploader.cancel();

Finalizes the upload. Signals that all files have been added and the Package is ready for delivery.

uploader.finalize();

Terminates the uploader instance and all of its workers. Use this to clean up resources when the uploader is no longer needed.

uploader.terminate();

Returns statistics about the uploader’s performance, including throughput and transfer metrics.

const stats = uploader.getPerformanceStats();

The file object format expected by addFiles().

PropertyTypeDescription
idstringA unique identifier for this file upload.
fileFileThe browser File object.
pathstringThe file path used to preserve folder structure on the receiving end. Use "" for flat uploads.

Subscribe to events using the on() method. You can listen for a specific event or delegate a handler for all events.

uploader.on(Uploader.UploaderEvents.Progress, (event) => {
console.log(event);
});
const handlers = {
[Uploader.UploaderEvents.Progress]: (e) => console.log("Progress:", e),
[Uploader.UploaderEvents.Finished]: (e) => console.log("Done:", e),
};
uploader.on("emit", (event) => {
if (event.name in handlers) {
handlers[event.name](event);
}
});

Every event callback receives an object with the following structure:

PropertyTypeDescription
eventstringThe event name (one of the values listed in the table below).
timenumberA Unix timestamp indicating when the event was fired.
targetobjectThe uploader module that fired the event.
dataobjectEvent-specific data relevant to the event type.
ConstantString ValueDescription
Createduploader:createThe uploader instance is initialized.
Startupload:startThe uploader begins uploading data — either at the start of the upload or after a pause.
FileQueuedupload:file_queuedA file is queued for upload.
Progressupload:progressData is successfully sent. Use this to update progress indicators.
Chunkupload:chunkA chunk of a file has finished uploading.
Fileupload:fileAll chunks for a file have finished uploading.
Finalizeupload:finalizeThe uploader has finalized a file upload.
Errorupload:errorAn error occurred during an upload request.
Finishedupload:finishThe uploader has finished uploading all files.
Abortupload:abortAn upload is aborted, typically when the uploader is paused.
Retryupload:retryThe uploader is retrying a request, usually due to a network issue.
File Unreadableupload:file_unreadableThe browser is unable to read one of the files in the Package.
Stalledupload:stalledNo upload progress has been reported for at least 1 minute.

Events are accessed via the Uploader.UploaderEvents enum:

Uploader.UploaderEvents.Progress // "upload:progress"
Uploader.UploaderEvents.Finished // "upload:finish"
Uploader.UploaderEvents.Error // "upload:error"
// ... etc.