Dropzone
Overview
Dropzone.js is a light weight JavaScript library that turns an HTML element into a dropzone. This means that a user can drag and drop a file onto it, and the file gets uploaded to the server via AJAX. Dropzone does not handle your file uploads on the server. You have to implement the code to receive and store the file yourself.
Main features:
- Image thumbnail previews. Simply register the callback
thumbnail(file, data)
and display the image wherever you like - Retina enabled
- Multiple files and synchronous uploads
- Progress updates
- Support for large files
- Complete theming. The look and feel of Dropzone is just the default theme. You can define everything yourself by overwriting the default event listeners.
- Well tested
Usage
Include the following lines of code in the <head>
section of your HTML:
<!-- Load jQuery -->
<script src="../../../../global_assets/js/main/jquery.min.js"></script>
<!-- Load plugin -->
<script src="../../../../global_assets/js/plugins/uploaders/dropzone.min.js"></script>
Add form element with attributes:
<!-- Add form markup -->
<form action="#" class="dropzone" id="dropzone_multiple"></form>
Call the plugin via JavaScript:
// Multiple files upload
$("#dropzone_multiple").dropzone({
paramName: "file", // The name that will be used to transfer the file
dictDefaultMessage: 'Drop files to upload <span>or CLICK</span>',
maxFilesize: 0.1 // MB
});
Plugin options
Option | Description |
---|---|
Core options | |
url |
Has to be specified on elements other than form (or when the form doesn't have an action attribute). You can also provide a function that will be called with files and must return the url |
method |
Defaults to "post" and can be changed to "put" if necessary. You can also provide a function that will be called with files and must return the method |
parallelUploads |
How many file uploads to process in parallel |
maxFilesize |
in MB |
filesizeBase |
Defaults to 1000. This defines whether a base of 1000 or 1024 should be used to calculate file sizes. 1000 is correct, because 1000 Bytes equal 1 Kilobyte, and 1024 Bytes equal 1 Kibibyte. You can change this to 1024 if you don't care about validity. |
paramName |
The name of the file param that gets transferred. Defaults to file . NOTE: If you have the option uploadMultiple set to true , then Dropzone will append [] to the name. |
uploadMultiple |
Whether Dropzone should send multiple files in one request. If this it set to true, then the fallback file input element will have the multiple attribute as well. This option will also trigger additional events (like processingmultiple ) |
headers |
An object to send additional headers to the server. Eg: headers: { "My-Awesome-Header": "header value" } |
addRemoveLinks |
This will add a link to every file preview to remove or cancel (if already uploading) the file. The dictCancelUpload , dictCancelUploadConfirmation and dictRemoveFile options are used for the wording. |
previewsContainer |
Defines where to display the file previews – if null the Dropzone element is used. Can be a plain HTMLElement or a CSS selector. The element should have the dropzone-previews class so the previews are displayed properly. |
clickable |
If true , the dropzone element itself will be clickable, if false nothing will be clickable. Otherwise you can pass an HTML element, a CSS selector (for multiple elements) or an array of those. |
maxThumbnailFilesize |
In MB. When the filename exceeds this limit, the thumbnail will not be generated. |
thumbnailWidth |
If null , the ratio of the image will be used to calculate it. |
thumbnailHeight |
The same as thumbnailWidth . If both are null , images will not be resized. |
maxFiles |
If not null defines how many files this Dropzone handles. If it exceeds, the event maxfilesexceeded will be called. The dropzone element gets the class dz-max- files-reached accordingly so you can provide visual feedback. |
resize |
Is the function that gets called to create the resize information. It gets the file as first parameter and must return an object with srcX , srcY , srcWidth and srcHeight and the same for trg* . Those values are going to be used by ctx.drawImage() . |
init |
Is a function that gets called when Dropzone is initialized. You can setup event listeners inside this function. |
acceptedFiles |
The default implementation of accept checks the file's mime type or extension against this list. This is a comma separated list of mime types or file extensions. Eg.: image/*,application/pdf,.psd . If the Dropzone is clickable this option will be used as accept parameter on the hidden file input as well. |
accept |
Is a function that gets a file and a done function as parameter. If the done function is invoked without a parameter, the file will be processed. If you pass an error message it will be displayed and the file will not be uploaded. This function will not be called if the file is too big or doesn't match the mime types. |
autoProcessQueue |
When set to false you have to call myDropzone.processQueue() yourself in order to upload the dropped files. See below for more information on handling queues. |
previewTemplate |
Is a string that contains the template used for each dropped image. Change it to fulfill your needs but make sure to properly provide all elements. You can include the HTML in your page in a <div id="preview-template" style="display: none;"></div> container, and set it like this: previewTemplate: document.querySelector('preview-template').innerHTML . |
forceFallback |
Defaults to false . If true the fallback will be forced. This is very useful to test your server implementations first and make sure that everything works as expected without dropzone if you experience problems, and to test how your fallbacks will look. |
fallback |
Is a function that gets called when the browser is not supported. The default implementation shows the fallback input field and adds a text. |
To translate dropzone, you can also provide these options: | |
dictDefaultMessage |
The message that gets displayed before any files are dropped. This is normally replaced by an image but defaults to "Drop files here to upload" |
dictFallbackMessage |
If the browser is not supported, the default message will be replaced with this text. Defaults to "Your browser does not support drag'n'drop file uploads." |
dictFallbackText |
This will be added before the file input files. If you provide a fallback element yourself, or if this option is null this will be ignored. Defaults to "Please use the fallback form below to upload your files like in the olden days." |
dictInvalidFileType |
Shown as error message if the file doesn't match the file type. |
dictFileTooBig |
Shown when the file is too big. {{filesize}} and {{maxFilesize}} will be replaced. |
dictResponseError |
Shown as error message if the server response was invalid. {{statusCode}} will be replaced with the servers status code. |
dictCancelUpload |
If addRemoveLinks is true , the text to be used for the cancel upload link. |
dictCancelUploadConfirmation |
If addRemoveLinks is true , the text to be used for confirmation when cancelling upload. |
dictRemoveFile |
If addRemoveLinks is true , the text to be used to remove a file. |
dictMaxFilesExceeded |
If maxFiles is set, this will be the error message when it's exceeded. |
Plugin events
Do not overwrite those as configuration options, unless you know what you're doing:
Event | Description |
---|---|
All of these receive the event as first parameter: |
|
drop |
The user dropped something onto the dropzone |
dragstart |
The user started to drag anywhere |
dragend |
Dragging has ended |
dragenter |
The user dragged a file onto the Dropzone |
dragover |
The user is dragging a file over the Dropzone |
dragleave |
The user dragged a file out of the Dropzone |
All of these receive the file as first parameter: |
|
addedfile |
When a file is added to the list |
removedfile |
Called whenever a file is removed from the list. You can listen to this and delete the file from your server if you want to |
thumbnail |
When the thumbnail has been generated. Receives the dataUrl as second parameter |
error |
An error occured. Receives the errorMessage as second parameter and if the error was due to the XMLHttpRequest the xhr object as third |
processing |
When a file gets processed (since there is a queue not all files are processed immediately) |
uploadprogress |
Gets called periodically whenever the file upload progress changes. Gets the progress parameter as second parameter which is a percentage (0-100) and the bytesSent parameter as third which is the number of the bytes that have been sent to the server. When an upload finishes dropzone ensures that uploadprogress will be called with a percentage of 100 at least once. Warning: This function can potentially be called with the same progress multiple times |
sending |
Called just before each file is sent. Gets the xhr object and the formData objects as second and third parameters, so you can modify them (for example to add a CSRF token) or add additional data |
success |
The file has been uploaded successfully. Gets the server response as second argument |
complete |
Called when the upload was either successful or erroneous |
canceled |
Called when a file upload gets canceled |
maxfilesreached |
Called when the number of files accepted reaches the maxFiles limit |
maxfilesexceeded |
Called for each file that has been rejected because the number of files exceeds the maxFiles limit |
All of these receive a list of files as first parameter and are only called if the uploadMultiple option is true : |
|
processingmultiple |
See processing for description |
sendingmultiple |
See sending for description |
successmultiple |
See success for description |
completemultiple |
See complete for description |
canceledmultiple |
See canceled for description |
Special events: | |
totaluploadprogress |
Called with the total uploadProgress (0-100), the totalBytes and the totalBytesSent . This event can be used to show the overall upload progress of all files |
reset |
Called when all files in the list are removed and the dropzone is reset to initial state |
queuecomplete |
Called when all files in the queue finish uploading |
Plugin info
Property | Description |
---|---|
File name | dropzone.min.js |
Location | global_assets/js/plugins/uploaders/ |
Links | Github project page |
Plupload
Overview
Plupload is a cross-browser multi-runtime file uploading API. Basically, a set of tools that will help you to build a reliable and visually appealing file uploader in minutes.
Historically, Plupload comes from a dark and hostile age of no HTML5, hence all the alternative fallbacks, like Flash, Silverlight and Java (still in development). It is meant to provide an API, that will work anywhere and in any case, in one way or another. While having very solid fallbacks, Plupload is built with the future of HTML5 in mind.
Usage
Include the following lines of code in the <head>
section of your HTML:
<!-- Load jQuery -->
<script src="../../../../global_assets/js/main/jquery.min.js"></script>
<!-- Load plugin -->
<script src="../../../../global_assets/js/plugins/uploaders/plupload/plupload.full.min.js"></script>
<!-- Load plugin extension -->
<script src="../../../../global_assets/js/plugins/uploaders/plupload/plupload.queue.min.js"></script>
Add element with attributes:
<!-- All runtimes example -->
<div class="file-uploader">
<p>Your browser doesn't have Flash installed.</p>
</div>
Call the plugin via JavaScript:
// All runtimes example
$(".file-uploader").pluploadQueue({
runtimes: 'html5, html4, Flash, Silverlight',
url: 'assets/demo_data/uploader/plupload.json',
chunk_size: '300Kb',
unique_names: true,
filters: {
max_file_size: '300Kb',
mime_types: [{
title: "Image files",
extensions: "jpg,gif,png"
}]
},
resize: {
width: 320,
height: 240,
quality: 90
}
});
Plupload documentation
Complete Plupload documentation can be found online on Official library website. It's quite big, with a lot of options, events, methods and file filters. Also check out FAQ section and translating options. I find it useless to copy them all and paste to the Limitless documentation, nobody can represent and describe library features better than its creators. Below you can find additional links related to Plupload library.
Plugin info
Property | Description |
---|---|
File name | plupload.full.min.js, moxie.min.js, plupload.queue.min.js |
Location | global_assets/js/plugins/uploaders/plupload/ |
Links | Github project page |
Bootstrap file upload
Overview
An enhanced HTML 5 file input for Bootstrap 3.x with file preview for various files, offers multiple selection, and more. The plugin allows you a simple way to setup an advanced file picker/upload control built to work specially with Bootstrap CSS3 styles. It enhances the file input functionality further, by offering support to preview a wide variety of files i.e. images, text, html, video, audio, flash, and objects.
In addition, it includes AJAX based uploads, dragging & dropping files, viewing upload progress, and selectively previewing, adding, or deleting files.
Usage
Include the following lines of code in the <head>
section of your HTML:
<!-- Load jQuery -->
<script src="assets/js/main/jquery.min.js"></script>
<!-- Load Bootstrap -->
<script src="../../../../global_assets/js/core/libraries/bootstrap.min.js"></script>
<!-- Load plugin -->
<script src="../../../../global_assets/js/plugins/uploaders/fileinput.min.js"></script>
Add file input element with attributes:
<!-- Single file -->
<input type="file" class="file-input">
<!-- Multiple files -->
<input type="file" class="file-input" multiple="multiple">
Call the plugin via JavaScript:
// Basic setup
$('.file-input').fileinput({
browseLabel: '',
browseClass: 'btn btn-primary btn-icon',
removeLabel: '',
uploadLabel: '',
uploadClass: 'btn btn-default btn-icon',
browseIcon: '<i class="icon-plus22"></i> ',
uploadIcon: '<i class="icon-file-upload"></i> ',
removeClass: 'btn btn-danger btn-icon',
removeIcon: '<i class="icon-cancel-square"></i> ',
layoutTemplates: {
caption: '<div tabindex="-1" class="form-control file-caption {class}">\n' + '<span class="icon-file-plus kv-caption-icon"></span><div class="file-caption-name"></div>\n' + '</div>'
},
initialCaption: "No file selected"
});
Bootstrap file input documentation
Complete BS file input documentation can be found online on Official library website. It's quite big, with tons of options, events, methods and AJAX uploads options. I find it useless to copy them all and paste to the Limitless documentation, nobody can represent and describe library features better than its creators. Below you can find additional links related to BS file input library.
Plugin info
Property | Description |
---|---|
File name | fileinput.min.js |
Location | global_assets/js/plugins/uploaders/ |
Links | Github project page |