1.0.0-beta.12 • Published 5 years ago

nifty-uploader v1.0.0-beta.12

Weekly downloads
1
License
MIT
Repository
github
Last release
5 years ago

Nifty Uploader

Build Status codecov
An easy file uploader for the browser written in TypeScript.

Features

  • upload in chunks
  • concurrent uploads
  • add files to uploader
  • cancel uploads
  • retry uploads
  • get progress of file/chunk or total progress
  • validate filesize and filetype
  • limit the total file size of all files
  • add custom validation
  • add custom headers to request
  • add custom request parameters
  • event system

API

NiftyUploader(options)

Options

optiontypedefaultdescription
chunkingbooleantrueEnable or disable chunking. Uploads file in smaller pieces.
chunksizenumber2 * 1024 * 1024The size of each chunk.
endpointstring/The server endpoint of the uploader. Sends request to this address.
numberOfConcurrentUploadsnumber3Number of concurrent uploads.
generateUniqueIdentifier(file: NiftyFile) => string \| Promise<string>undefinedThe function to generate the unique identifier, which returns a string with the identifier. It can also return a Promise.
customRequestParameters{ [key: string]: string \| number }{}POST request parameter, which will be send with every request.
customHeaders{ [key: string]: string \| number }{}Request headers, which will be send with every request.
autoUploadbooleantrueDetermines if the queue of files should be uploaded automatically.
autoQueuebooleantrueDetermines if a successfully processed file should be added automatically to the queue.
autoProcessbooleantrueDetermines if an added file should be processed automatically.
maxRetriesnumber3The number of retries before the file will be rejected.
retryDelaynumber100The delay between the attempts to retry an upload.
permanentErrornumber[][400, 404, 409, 415, 500, 501]An array of HTTP status codes, which rejects the file without retrying.
minFileSizenumber1The minimum size of a file.
maxFileSizenumberundefinedThe maximum size of a file.
totalFileSizeLimitnumberundefinedThe maximum size of all file sizes in the uploader combined.
allowedFileTypesstring[][]The allowed file types. You can use .ext, ext, mime/type or mime/*. An empty array (default) allows all file types.
customValidation(file: NiftyFile) => Promise<any>undefinedA custom function, which will be called in the processing step. The function takes the NiftyFile as an argument and must return a Promise. The reject() of the Promise can take a string, which is used as an error message.
Example initialization with options
var uploader = new NiftyUploader({
    endpoint: '/backend.php',
    numberOfConcurrentUploads: 2
})