Limit amount of files in DropZone.js

0

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?

    
asked by anonymous 29.06.2015 / 20:48

2 answers

0

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!");
      }
    });
  }
};
    
29.06.2015 / 21:00
2

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"

    });
    
29.06.2015 / 20:57