GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up Dropzone is an easy to use drag'n'drop library.
![]()
Long battery lifeWith up to 1 week standby time and up to 50 hours of GPS navigation, you can have worry-free adventures with X2.GPSBring your situational awareness to the next level by combining altitude awareness and location awareness.BluetoothX2 works with your Android or iOS smartphone wirelessly. Download jump logs, set GPS waypoints and more.High-resolution colour screenEnhance your situational awareness with flight data displayed on our large, high-resolution 2.7″ LCD screen with excellent clarity in bright sunlight.DZ navigationArrow indicators for DZ heading and distance, and set up waypoints for navigation.Built for any landingX2 has IPX7 waterproof rating and can be fully submerged in fresh water or salt water down to 1 metre depth.
Landed in the swoop pond?
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.
If you want support, please use stackoverflow with the
dropzone.js tag and not theGitLab issues tracker. Only post an issue here if you think you discovered a bug or have a feature request.
![]()
Please read the contributing guidelines before you start working on Dropzone!
Dropzone does not depend on jQuery.
Dropzone is compatible with bower, there's a standalone version of Dropzone, an AMDmodule that's compatible with RequireJS in the downloadsfolder.
Main features
Documentation
For the full documentation and installation please visit www.dropzonejs.com
Please also refer to the FAQ.
Examples
For examples, please see the GitLab wiki.
You probably only need to look at the simple example (source)to get started. Continue reading for step by step instructions and differentinstallation approaches.
Download the standalone dropzone.jsand include it like this:
Dropzone is now activated and available as
window.Dropzone .
Dropzone does not handle your file uploads on the server. You have to implementthe code to receive and store the file yourself. See the sectionServer side implementation for more information.
This is all you need to get dropzone up and running, but if you want it to looklike the dropzone on this page, you’ll need to use the dropzone.cssin the dist folder.
With RequireJS
Dropzone is also available as an AMD modulefor RequireJS.
You can find the dropzone-amd-modulein the dist folder.
The typical way of using dropzone is by creating a form element with the class
dropzone :
That’s it. Dropzone will find all form elements with the class dropzone,automatically attach itself to it, and upload files dropped into it to thespecified
action attribute. The uploaded files can be handled just as ifthere would have been a html input like this:
If you want another name than
file you can configure dropzonewith the option paramName .
If you want your file uploads to work even without JavaScript, you can includean element with the class
fallback that dropzone will remove if the browseris supported. If the browser isn’t supported, Dropzone will not create fallbackelements if there is a fallback element already provided. (Obviously, if thebrowser doesn’t support JavaScript, the form will stay as is)
Typically this will look like this:
Create dropzones programmatically
Alternatively you can create dropzones programmaticaly (even on non
form elements) by instantiating the Dropzone class
or if you use jQuery, you can use the jQuery plugin Dropzone ships with:
Don’t forget to specify an
url option if you’re not using a form element,since Dropzone doesn’t know where to post to without an action attribute.
Server side implementation
Dropzone does not provide the server side implementation of handling the files,but the way files are uploaded is identical to simple file upload forms like this:
To handle basic file uploads on the server, please look at the correspondingdocumentation. Here are a few documentations, if you think I should add some,please contact me.
Paid documentations:
Please look at the Dropzone FAQ ifyou need more information.
There are two ways to configure dropzones.
The obvious way is to pass an options object when instantiating a dropzoneprogrammatically like in the previous create dropzones programmaticallysection.
But if you just have HTML elements with the
dropzone class, then you don’tprogrammatically instantiate the objects, so you have to store the configurationsomewhere so Dropzone knows how to configure the dropzones when instantiatingthem.
This is done with the
Dropzone.options object.
If you want to disable the auto discover behaviour of Dropzone, you can either disableit on a per element basis, or in general:
You can also overwrite all default event actions in the options. So if you provide the option
drop you can overwrite the default drop event handler.You should be familiar with the code if you do that because you can easily break the upload like this.If you just want to do additional stuff, like adding a few classes here and there, listen to the events instead!
Enqueuing file uploads
When a file gets added to the dropzone, its
status gets set to Dropzone.QUEUED (after the accept function check passes) which means that the file is nowin the queue.
If you have the option
autoProcessQueue set to true then the queue is immediatelyprocessed, after a file is dropped or an upload finished, by calling.processQueue() which checks how many files are currently uploading,and if it’s less than options.parallelUploads , .processFile(file) is called.
If you set
autoProcessQueue to false , then .processQueue() is never calledimplicitly. This means that you have to call it yourself when you want toupload all files currently queued.
Layout
The HTML that is generated for each file by dropzone is defined with the option
previewTemplate which defaults to this:
The container (
dz-preview ) gets the dz-processing class when the file gets processed, dz-success when the file got uploaded and dz-error in case the file couldn’t be uploaded.In the latter case, data-dz-errormessage will contain the text returned by the server.
To overwrite the default template, use the
previewTemplate config.
You can access the HTML of the file preview in any of the events with
file.previewElement .
If you decide to rewrite the
previewTemplate from scratch, you should put elements with the data-dz-* attributes inside:
The default options for Dropzone will look for those element and update the content for it.
If you want some specific link to remove a file (instead of the built in
addRemoveLinks config), you can simply insert elementsin the template with the data-dz-remove attribute. Example:
You are not forced to use those conventions though. If you override all the default event listenersyou can completely rebuild your layout from scratch.
See the installation section on how to add the stylesheet and spritemaps if you want your dropzone to look like the one on this page.
See the Theming section, for a more in depth look at how to change Dropzone’s UI.
I created an example where I made Dropzone look and feel exactly the way jQueryFile Uploader does with a few lines of configuration code. Check it out!
Again, please look at the Dropzone FAQ ifyou’re still unclear about some features.
Dropzone methods
If you want to remove an added file from the dropzone, you can call
.removeFile(file) .This method also triggers the removedfile event.
Here’s an example that would automatically remove a file when it’s finished uploading:
If you want to remove all files, simply use
.removeAllFiles() . Files that arein the process of being uploaded won’t be removed. If you want files that arecurrently uploading to be canceled, call .removeAllFiles(true) which willcancel the uploads.
If you have
autoProcessQueue disabled, you’ll need to call .processQueue() yourself.
This can be useful if you want to display the files and let the user click anaccept button to actually upload the file(s).
To access all files in the dropzone, use
myDropzone.files .
To get
If you do not need a dropzone anymore, just call
.disable() on the object. Thiswill remove all event listeners on the element, and clear all file arrays. Toreenable a Dropzone use .enable() .
If you don’t like the default browser modals for
confirm calls,you can handle them yourself by overwriting Dropzone.confirm .
If you want Dropzone to download a file from your server and display it,you can use
See the FAQ on How to show files stored on serverfor more information.
Dropzone triggers events when processing files, to which you can register easily,by calling
.on(eventName, callbackFunction) on your instance.
Since listening to events can only be done on instances of Dropzone, the bestplace to setup your event listeners, is in the
init function:
If you create your Dropzones programmatically,you can setup your event listeners on your instances, like this:
This is a bit more complex, and not necessary unless you have a good reasonto instantiate Dropzones programmatically.
Dropzone itself relies heavily on events. Everything that’s visual is createdby listening to them. Those event listeners are setup in the default configurationof every Dropzone and can be overwritten, thus replacing the default behaviorwith your own event callback.
You should only do this when you really know how Dropzone works, and when youwant to completely theme your Dropzone
Theming
If you want to theme your Dropzone to look fully customized, in most cases youcan simply replace the preview HTML template, adapt your CSS, and maybe createa few additional event listeners.
You will go very far with this approach. As an example, I created an examplewhere I made Dropzone look and feel exactly the way jQuery File Uploader doeswith a few lines of configuration code. Check it out!
As you can see, the biggest change is the
previewTemplate . I then added a fewadditional event listeners to make it look exactly like the reference.
You can however, implement your UI completely from scratch.
Dropzone itself sets up a lot of event listeners when a Dropzone is created,that handle all your UI. They do stuff like: create a new HTML element,add the
<img> element when provided with image data (with the thumbnail event),update the progress bar when the uploadprogress event fires,show a checkmark when the success event fires,etc...
Everything visual is done in those event handlers. If you would overwrite allof them with empty functions, Dropzonewould still be fully functional, but wouldn’t display the dropped files anymore.
If you like the default look of Dropzone, but would just like to add a fewbells and whistles here and there, you should just add additional eventlisteners instead.
Overwriting the default event listeners, and creating your own, custom Dropzone,would look something like this:
Obviously this lacks the actual implementation. Look at the source to see howDropzone does it internally.
You should use this option if you don’t need any of the default Dropzone UI,but are only interested in Dropzone for it’s event handlers, file upload anddrag’n’drop functionality.
If you do not want the default message at all (»Drop files to upload (or click)«), you canput an element inside your dropzone element with the class
dz-message and dropzonewill not create the message for you.
Dropzone will submit any hidden fields you have in your dropzone form. So thisis an easy way to submit additional data. You can also use the
params option.
Dropzone adds data to the
file object you can use when events fire. You canaccess file.width and file.height if it’s an image, as well asfile.upload which is an object containing: progress (0-100), total (thetotal bytes) and bytesSent .
If you want to add additional data to the file upload that has to be specific foreach file, you can register for the
sending event:
To access the preview html of a file, you can access
file.previewElement . Forexample:
If you want the whole body to be a Dropzone and display the files somewhere elseyou can simply instantiate a Dropzone object for the body, and define the
previewsContainer option. The previewsContainer should have thedropzone-previews or dropzone class to properly display the file previews.
Look at the gitlab wiki for more examples.
If you have any problems using Dropzone, please try to find help onstackoverflow.com by using the
dropzone.js tag.Only create an issue on Github when you think you found a bug or want tosuggest a new feature.
This section describes compatibility with browsers and older versions ofDropzone.
Browser Support
For all the other browsers, dropzone provides an oldschool file input fallback.
There is no workaround for drag’n’drop in older browsers – it simply isn'tsupported. The same goes for image previews, etc... But using dropzone, yourusers using an old browser will be able to upload files. It just won’t lookand feel great. But hey, that’s their fault.
Version 5.0
Version 4.0
Version 3.0
Version 2.0
Starting with version 2.0, Dropzone no longer depends on jQuery, but Dropzonestill registers itself as a jQuery module if available.
That means that creating your Dropzones like this still works:
If you create your Dropzones with the normal constructor though, you have topass either the raw HTMLElement, or a selector string. So those versions allwork:
Another thing that changed, is that Dropzone no longer stores its instancesinside the element’s data property. So to get a dropzone for an element do thisnow:
I realize that there arealreadyotherlibraries out there but the reason I decided to write my own are the following:
See LICENSE file
![]() Comments are closed.
|
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
January 2023
Categories |