This example uploads a single file using dropzone js library. By default, dropzone is a multiple file uploader and does not have specific option allowing us to switch to single file uploading mode, but this functionality can be achieved by adding more options to the plugin settings, such as maxfilesexceeded
callback and maxFiles
option set to 1. maxFiles: 1
is used to tell dropzone that there should be only one file. When there is more then 1 file the function maxfilesexceeded
will be called, with the exceeding file in the first parameter. Now only 1 file can be selected and it will be replaced with another one instead of adding it to the preview.
This example uploads a multiple files using dropzone js library. By default, dropzone is a multiple file uploader. User can either click on the dropzone area and select multiple files or just drop all selected files in the dropzone area. This example is the most basic setup for dropzone.
This example uploads a multiple files using dropzone js library. Using this method, user gets an option to select the files using a button instead dropping all the files after selected from the folders. You have to define dropzone
and previewsContainer
elements to show preview thumbnails. Also set clickable
to match the button's id for button to work as file selector.
In many case user must be limited to upload certain no. of files. You can always set the maxFiles
option to limit no. of upload files. maxfilesexceeded
event will be called if uploads exceeds the limit. Also, if you want to limit the file size of uploads then set the maxFilesize
option. Define the maximum file size to be uploded in MBs like 0.5
MB as is in this example. User can also define maxThumbnailFilesize
in MB. When the uploaded file exceeds this limit, the thumbnail will not be generated.
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.
dz-message
and dropzone will not create the message for you.params
option.file
object you can use when events fire. You can access file.width
and file.height
if it’s an image, as well as file.upload
which is an object containing: progress
(0-100), total
(the total bytes) and bytesSent
.sending
event:
myDropzone.on("sending", function(file, xhr, formData) {
// Will send the filesize along with the file as POST data.
formData.append("filesize", file.size);
});
file.previewElement
. For example:
myDropzone.on("addedfile", function(file) {
file.previewElement.addEventListener("click", function() {
myDropzone.removeFile(file);
});
});
previewsContainer
option. The previewsContainer
should have the dropzone-previews
or dropzone
class to properly display the file previews.
new Dropzone(document.body, {
previewsContainer: ".dropzone-previews",
// You probably don't want the whole body
// to be clickable to select files
clickable: false
});