presto.js is a small JavaScript library for file upload.
Main features are:
- Faster than normal file uploading - by splitting files into small chunks and uploading them simultaneously.
- Work well for lots of huge size files.
- Chrome (desktop & mobile)
- Firefox
- Microsoft Edge 16+ (Some examples works with 17+)
- Safari 11+ (desktop & mobile)
<form class="uploadForm">
<input type="file" multiple />
<input type="submit" value="Upload" />
</form>const formEl = document.querySelector('.uploadForm');
new Presto({ element: formEl, url: 'DESTINATION_URL' });Server side examples:
const presto = new Presto({ url: '/api/upload', ... });url: [string] URL of upload destination. (Default:'')chunkSize: [integer] Size (byte) of each chunk (Default:1048576 //1MB)simultaneous: [integer] Number of chunks to send abreast. 6 is recommended for HTTP/1.1 and 10 is recommended for HTTP/2. (Default:6)element: [HTMLFormElement] If specified, the upload will start automatically when the form is submitted. The element must have a HTMLFormInput[type="file"] as a child. (Default:null)uniqueIdGenerator: [function] A custom function that defines a unique ID for each file. The ID is sent with each chunk. (Default:fileObject => {return `presto_${UUID_V4_STRING}`; })httpHeaders: [function] A custom function to add HTTP headers to each chunk send request. (Default:PrestoFile => {return {}; })withCredentials: [boolean] This value is used as the withCredentials option of the chunk send request(XMLHttpRequest). Settrueto send cookies with cross domain request. (Default:false)
Presto.fileList: [array] Array of PrestoFile.PrestoFile.prestoId: [string] Unique ID of PrestoFile.PrestoFile.name: [string] File name.PrestoFile.size: [integer] File size (byte).PrestoFile.displaySize: [string] Human readable file size.
Presto.on(string eventName, function callback): Add event listener to Presto.Presto.off(string eventName, function callback): Remove event listener from Presto.Presto.add(HTML5 FileList object, object optional form data): Add file(s) to Presto.Presto.remove(string prestoId): Remove file from Presto. If nothing is specified, remove all files.Presto.reset(HTML5 FileList object, object optional form data): ReplacePresto.fileListwith specified file list. If nothing is specified, remove all files.Presto.send(string prestoId): Start file upload of the specified file. If nothing is specified, upload all files.Presto.abort(string prestoId): Abort file upload of the specified file. If nothing is specified, abort all files.Presto.progress(string prestoId): Return upload progress (float number between 0 - 1) of the specified file. If nothing is specified, return progress for all files.
Presto offers the following events:
added: Fires when file is added. Returns array ofPrestoFile.removed: Fires when file(s) is removed. Returns array of removed file ID.reset: Fires whenPresto.fileListis reset.start: Fires when uploading is started.abort: Fires when uploading is aborted.complete: Fires when uploading is completed. Returns duration of uploading(msec).progress: Fires whenever chunk upload succeeds. Returns progress for all files(float number between 0 - 1).fileStart: Fires whenever uploading of each file is started. ReturnsPrestoFile.fileAbort: Fires whenever uploading of each file is aborted. ReturnsPrestoFile.fileComplete: Fires whenever uploading of each file is completed. ReturnsPrestoFile.fileProgress: Fires whenever chunk upload succeeds. ReturnsfileProgress(float number between 0 - 1),PrestoFile.fileError: Fires when chunk upload fails. ReturnschunkIndex,HTTP status code,HTTP status text,PrestoFile.
PrestoFile offers the following events:
start: Fires when upload started. ReturnsPrestoFile.abort: Fires when upload aborted. ReturnsPrestoFile.complete: Fires when upload completed. ReturnsPrestoFile.progress: Fires whenever chunk upload succeed. ReturnsfileProgress(float number between 0 - 1),PrestoFile.error: Fires when chunk upload failed. ReturnschunkIndex,XMLHttpRequest.status,XMLHttpRequest.statusText,PrestoFile.
The idea of simultaneous upload came from resumable.js and flow.js.
Presto project is spun off from the jPOST project.