Dropzone
Search…
Basics
In this section we'll co over the fundamentals of configuring Dropzones.
You should already be familiar on how to pass a configuration object to Dropzone in the declarative and the imperative way. If not, please visit the respective sections.
This is what a typical configuration of Dropzone would look like:
Declarative
Imperative
1
<form action="/target" class="dropzone" id="my-great-dropzone"></form>
2
3
<script>
4
Dropzone.options.myGreatDropzone = { // camelized version of the `id`
5
paramName: "file", // The name that will be used to transfer the file
6
maxFilesize: 2, // MB
7
accept: function(file, done) {
8
if (file.name == "justinbieber.jpg") {
9
done("Naha, you don't.");
10
}
11
else { done(); }
12
}
13
};
14
</script>
Copied!
1
import Dropzone from "dropzone";
2
3
let myDropzone = Dropzone({
4
paramName: "file", // The name that will be used to transfer the file
5
maxFilesize: 2, // MB
6
accept: function(file, done) {
7
if (file.name == "justinbieber.jpg") {
8
done("Naha, you don't.");
9
}
10
else { done(); }
11
}
12
});
Copied!
For a list of all possible options, refer to the src/options.js file.

Events

If you want to react to events happening (a file has been added or removed, an upload started, a progress changed, etc...) you want to be listening to events. Checkout the events section for more information on events.

Overriding default event handlers

In general you should never have to do this, and you should be familiar with the code if you decide to do it.
You can also override default event handlers. This should be approached with absolute caution since it can break if you upgrade the library and can also remove default functionality that you might not want to lose:
1
let myDropzone = Dropzone("#my-element", {
2
addedfile: file => {
3
// ONLY DO THIS IF YOU KNOW WHAT YOU'RE DOING!
4
}
5
});
Copied!
The difference here, is that the default event handler addedfile has been changed, instead of adding a new event handler with myDropzone.on("addedfile", () => {})
Last modified 7mo ago