upload-file - Simplified file upload
Some options is borrowed from jquery.upload
var Upload = ;
install
npm install upload-file --save
express demo
app;
API
constructor(options)
- {object}
options
required- {string}
options.dest
required
Upload path - {RegExp}
options.acceptFileTypes
The regular expression for allowed file types, matches against either file type or file name - {function}
options.rename(name, file)
Return filename for change the filename or path, name is the input file name, and file is a object - {number}
[options.maxNumberOfFiles=Infinity]
The limit of files to be uploaded - {number}
[options.minNumberOfFiles=1]
The minimum of files to be uploaded - {number}
[options.maxFileSize=Infinity]
The maximum allowed file size in bytes - {number}
[options.minFileSize=0]
The minimum allowed file size in bytes - {object}
options.messages
Error and info messages- message.maxNumberOfFiles
- message.minNumberOfFiles
- message.acceptFileTypes
- message.maxFileSize
- message.minFileSize
- message.invalidRequest
- {string}
upload.on(event, listener)
Inherit from node's EventEmitter
upload.parse(req)
Parse the http request
upload.cleanup()
If the form is invalid, you can invoke this method for clear unnecessary file
upload.error(msg)
Emit error event with msg
upload.fields
The fields of form, it's a object
name: 'value' city: '1' '2'
upload.files
The files of form, it's a obejct
file: filename: 'index.css' path: 'upload/path/index.css' type: 'text/css' size: 100 files: ... ... // If the file.filename is empty string, // it's means that user do not upload file with this file input
How to run upload demo
- cd
upload-file
modules path - npm install
- node express.js