Skip to content

Lightweight file uploader for NodeJS and jQuery with support for drag/drop, basic and custom validators and hooks for all the various events like progress etc

License

Notifications You must be signed in to change notification settings

burt202/lite-uploader

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

LiteUploader

This is a lightweight library for NodeJS and jQuery, aiming to make uploading files a doddle. With some useful options including basic validation, it is a good choice for any developer who is not so worried about supporting legacy browsers.

Features

  • file type and size validation
  • support for custom validators
  • hooks for all major events like progress, success, fail etc
  • drag/drop support
  • ability dynamically update the form data packet before each upload
  • upload multiple files as individual requests

NodeJS

npm install lite-uploader --save

Bower

bower install lite-uploader --save

Examples

See examples.md

Options

Name Type Default Description
script String (required) null the path to the script file that will handle the upload
ref String null The request argument name for the file form data. Will fallback to the name property of the file input field if not supplied.
rules Object {allowedFileTypes: null, maxSize: null} object where you can specify validation rules for the files to be uploaded - current supported rules are:
  • allowedFileTypes (list of comma-separated mime-types, wildcards such as image/* are also supported)
  • maxSize (in bytes)
params Object {} object of params to be sent to the server in addition to the files being uploaded
headers Object {} object of headers to be sent to the server
validators Array [] an array of functions that can take a File and return a validation result on it, see examples for usage
singleFileUploads Boolean false set to true to upload each file of a selection using an individual request
beforeRequest Function Delay the file upload request by returning a promise. Recieves the Files and the FormData. Expected to resolve with the FormData to continue. Reject to stop upload.

Events

Name Parameters Description
lu:errors event, errors triggered when errors are found, including built-in and custom validators - see 'Error Types' section for more
lu:start event, files triggered before any uploading starts
lu:before event, files triggered before any request to the server
lu:progress event, {percentage, files} triggered whilst uploading files
lu:success event, response triggered on upload success
lu:fail event, jqXHR triggered on upload failure
lu:cancelled event triggered on upload abort

Error Types

Below is an overview of the built-in error types that can be returned when validating files

  • type - when file mime type does not match any mime types supplied in the rule.allowedFileTypes option
  • size - when file size is above the size (in bytes) supplied in the rule.maxSize option
  • refRequired - when there is no name attribute on the file input and no 'ref' options is passed to the plugin
  • scriptRequired - when no 'script' option is passed to the plugin

Public API

startUpload()

Starts the upload

Name Type Default Description
files FileList (optional) null a list of files to be uploaded, takes priority over default mechanism if supplied

addParam(key, value)

Allows parameters to be added after plugin instantiation

Name Type Default Description
key String (required) n/a name of parameter to be added
value String (required) n/a value of parameter to be added

cancelUpload()

Allows the upload to be cancelled, triggers lu:cancelled

Name Type Default Description
No parameters

Browser Support

  • Chrome 45+
  • Firefox 34+
  • Edge 12+
  • Internet Explorer NO (because Promises and Object.assign are used)
  • Safari 9+
  • Opera 32+

Changelog

View the changelog here.

License

Licensed under the MIT License.

View the full license here.

About

Lightweight file uploader for NodeJS and jQuery with support for drag/drop, basic and custom validators and hooks for all the various events like progress etc

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages