dropzone

Dropzone max file only one and remove the second file


I just use my code like this

Dropzone.options.attachkyc = {
            maxFiles: 1,
            accept: function(file, done) {
            console.log("uploaded");
            done();
            },
            init: function() {
                this.on("maxfilesexceeded", function(file){
                    alert("No more files please!");
                });
            },
            addRemoveLinks: true,
            removedfile: function(file) {
                var name = file.name;        
                $.ajax({
                    type: 'POST',
                    url: host+'upload/unfile',
                    data: "id="+name,
                    dataType: 'html'
                });
                var _ref;
                return (_ref = file.previewElement) != null ? _ref.parentNode.removeChild(file.previewElement) : void 0;   

                //console.log();
            }
        };

When i upload second file is show alert "No more files please!", well is working taht file not uploaded, but my problem is, that second file i'm add it still show on my dropzone. My question is how i'm remove second file automaticly after i show the alert??


Solution

  • if you want to remove max file extended file you just have to use maxfilesexceeded method of dropzone

        init: function() {
             myDropzone.on("maxfilesexceeded", function (file) {
                    this.removeFile(file);
                });
        },
    

    or you can also used one other method too

      init: function() {
      myDropzone.on("addedfile", function (file) {
    
                    if (myDropzone.files.length === 1) {
                        alert("You can Select upto 1 Pictures for Venue Profile.", "error");
                        this.removeFile(file);
                    }
    
                });
     },