1.0.6 • Published 5 years ago

@herii/jquery-file-uploader v1.0.6

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

JQuery File Uploader

This is a javascript class that provides the ability to upload files through ajax and show the progress in an html progress bar

JqueryFileUploaderGif

Features:

  • Display the upload progress in a progress bar
  • Files custom/default validation
  • Automatic/Manual upload
  • Single/Multiple files upload
  • Optional files limit
  • Custom actions when a validation is succesful or not
  • Custom actions on a request error/success/abort
  • Enable/disable many of the features

Installation

You can install this package via

npm i @herii/jquery-file-uploader  

Or you can clone this repo here:

https://github.com/Heriberto-Juarez/JQuery-File-Uploader.git

You will need to call jQuery and the FileUploader.js file for the code to work. You will also need a way to upload files, for this project you can find upload.php file in php folder. Its a simple script that uploads files.

Usage:

Basic HTML

You will need a container The container is essential for the functionality. Inside the container there must be a input of type file and a progressbar.

Example:

<div id="container-test" class="custom-styles">
    <label for="img">Select File</label>
    <input type="file" name="img" id="img" data-url="php/upload.php" multiple>
    <progress value="0"></progress>
</div>

Javascript

For the javascript class to work, we need to identify the previously created container, ours have the id container-test

An object must be created an as a first argument the container must be passed, a second an optional argument is an object with settings.

let container = $("#container-test");
let my_file_uploader = new FileUploader(container, {autoSend: true});

Settings

PropertyDefault valueDescriptionOptional Example
errorempty functionA function executed in case of upload error
doneempty functionA function executed in case of successful upload
abortempty functionA function executed in case of an aborted upload
methodPOSTAjax method used to send files
validatetrueIndicates whether the files should be validated
autoSendfalseIndicates whether the files should be sent automatically
onValidempty functionA function executed in case of valid files selected
onInvalidempty functionA function executed in case of invalid files selected
onInvalidempty functionA function executed in case of invalid files selected
maxSize5242880The maximum size allowed for each file in bytes
maxFiles-1The maximum amount of files allowed, if the value is -1 then the script will allow unlimited files
dataObjectThe maximum size allowed for each file in bytes{key:value, key2: value}

Manipulate formats

Different projects require different file types, so you may want to allow different sets of file formats or types.

The next methods will allow you to manipulate the formats you allow.

The file types or formats are the file MIME Types: For example: image/png

  • .addFormat(f); Add the format f
  • .removeFormat(f); Remove the format f
  • setAllFormats(array_of_formats); Set the allowed formats to the ones contained inside the array

Tips:

  • Assign values to onValid and onInvalid callback functions to enable and disable a button such as in the example found at index.html
  • Check the example at index.html to understand the File uploader use.
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago