Skip to content Skip to sidebar Skip to footer

Dropzone - Max Files Not Working

I have tried setting up the limit of uploading files to only one. I have tried all the suggestions from the previous questions here but nothing worked for me. Each time I was able

Solution 1:

You are splitting the dropzone configuration into two different methods. And only the first one is being used the one that contains the url option, the second, that contains the maxFiles option is ignored.

You have to either include all the configuration inside the first method that creates dropzone programmatically like this:

Dropzone.autoDiscover = false;
var myDropzone = newDropzone("div#dropzoneFileUpload", {
    url: "/admin/upload",
    params: {
       _token: token
    },
    paramName: "file", // The name that will be used to transfer the filemaxFilesize: 2, // MBaddRemoveLinks: true,
    maxFiles: 1,
    init: function() {
      this.on("maxfilesexceeded", function() {
        if (this.files[1]!=null){
          this.removeFile(this.files[0]);
        }
      });
    },
    accept: function(file, done) {

    }
 });

Or with second method that uses the dropzone autodiscover feature, if your dropzone element has the id #dropzoneFileUpload do it like this:

Dropzone.options.dropzoneFileUpload = {
    url: "/admin/upload",
    params: {
       _token: token
    },
    paramName: "file", // The name that will be used to transfer the filemaxFilesize: 2, // MBaddRemoveLinks: true,
    maxFiles: 1,
    init: function() {
      this.on("maxfilesexceeded", function() {
        if (this.files[1]!=null){
          this.removeFile(this.files[0]);
        }
      });
    },
    accept: function(file, done) {

    }
};

Post a Comment for "Dropzone - Max Files Not Working"