I'm using the Dropzone.js plugin to upload images and I'm having to limit the amount of images I upload to it. For example I want to limit to 5 files in total. Then it can only send to the server and display the 5 files. How do I do this to him?
I'm using the Dropzone.js plugin to upload images and I'm having to limit the amount of images I upload to it. For example I want to limit to 5 files in total. Then it can only send to the server and display the 5 files. How do I do this to him?
HTML
<form class="dropzone" id="meuDropZone"></form>
JavaScript :
Dropzone.options.meuDropZone = {
accept: function(file, done) {
console.log("uploaded");
done();
},
init: function() {
this.on("addedfile", function() {
if (this.files[5]!=null){
this.removeFile(this.files[5]);
alert("Limite de 5 arquivos excedido!");
}
});
}
};
Just add maxFiles:
, remembering that the correct one is you also validate from the server side how many files are uploading.
$("div#myDropZone").dropzone({
url: "ACTION/SERVIDOR",
autoProcessQueue: true,
uploadMultiple: true,
parallelUploads: 1,
maxFilesize: 5,
<!--Adicione o Maximo de arquivos-->
maxFiles: 8,
acceptedFiles: "image/jpeg"
});