Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/kanety/jquery-simple-upload
https://github.com/kanety/jquery-simple-upload
Last synced: 2 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/kanety/jquery-simple-upload
- Owner: kanety
- License: mit
- Created: 2019-05-25T02:03:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2021-01-23T02:01:29.000Z (almost 4 years ago)
- Last Synced: 2024-08-10T04:21:54.603Z (5 months ago)
- Language: JavaScript
- Size: 29.3 KB
- Stars: 2
- Watchers: 3
- Forks: 3
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# jquery-simple-upload
A jquery plugin for ajax file upload.
## Dependencies
* jquery
## Installation
Install from npm:
$ npm install @kanety/jquery-simple-upload --save
## Usage
Build file input field:
```html
```
Then run:
```javascript
$('#input').simpleUpload({
url: 'YOUR_BACKEND_URL',
method: 'post'
});
```### Options
Add drop zone and progress message:
```html
``````javascript
$('#input').simpleUpload({
...
dropZone: '#drop_zone',
progress: '#progress'
});
```Set additional ajax options:
```javascript
$('#input').simpleUpload({
...
ajax: {
headers: {
'HEADER_KEY': 'HEADER_VALUE'
},
dataType: 'application/json',
timeout: 0,
async: true
}
});
```Set additional query parameters:
```javascript
$('#input').simpleUpload({
// set object
params: {
'KEY': 'VALUE'
},
// or set callback
params: function() {
return { 'KEY': 'VALUE' };
},
});
```### Validations
```javascript
$('#input').simpleUpload({
...
maxFileNum: 4,
maxFileSize: 10 * 1024 * 1024, // Bytes
allowedFileName: /\.txt$/,
allowedMimeType: /^text\//
}).on('upload:over', function(e, files) {
...
}).on('upload:invalid', function(e, files) {
// files[i].reason contains the rejected reason
...
});
```### Callbacks
```javascript
$('#input').simpleUpload({
...
}).on('upload:before', function(e, files) {
...
}).on('upload:after', function(e, files) {
...
}).on('upload:start', function(e, file, i) {
...
}).on('upload:progress', function(e, file, i, loaded, total) {
...
}).on('upload:end', function(e, file, i) {
...
}).on('upload:done', function(e, file, i) {
...
}).on('upload:fail', function(e, file, i) {
...
});
```## License
The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).