Sumit patel
Sumit patel

Reputation: 3903

Dropzone Js max File upload not work properly

Notes : i tired all questions & answer related this topic.

I use Dropzone js in my application. i want to restrict only 3 file Upload in my dropzone then work fine.

issue is i upload four Number file then my all previous three file remove. that is not correctly .

i want to only alert in upload (four number file). but previous first three File not remove .

Steps:

1. First three file Upload in dropzon.

2. Add one more File in Dropzone. Then alert mess. only and not Previous File Remove

My Code Here

Upvotes: 0

Views: 909

Answers (2)

Mahi
Mahi

Reputation: 1727

https://jsfiddle.net/mxxa0bk8/16/

 var accept = ".png";
Dropzone.autoDiscover = false;

// Dropzone class:
var myDropzone = new Dropzone("#mydropzone", { 
url: "/file/post",
 acceptedFiles: accept,
 uploadMultiple: false,
createImageThumbnails: false,
addRemoveLinks: true,
maxFiles: 3,
 maxfilesexceeded: function(file) {
     alert("No moar files please!");
},init: function() {
       this.on("maxfilesexceeded", function(file) {
this.removeFile(file);
});
this.on('error', function(file, errorMessage) {
  var mypreview = document.getElementsByClassName('dz-error');
  mypreview = mypreview[mypreview.length - 1];
  mypreview.classList.toggle('dz-error');
  mypreview.classList.toggle('dz-success');
});
 }

 });

Upvotes: 1

ardilgulez
ardilgulez

Reputation: 1944

The following code snippet will make your dropzone remove files when they are completed:

this.on("complete", function(file) {
  this.removeFile(file);
});

Add this right under:

this.on('error', function(file, errorMessage) {
  var mypreview = document.getElementsByClassName('dz-error');
  mypreview = mypreview[mypreview.length - 1];
  mypreview.classList.toggle('dz-error');
  mypreview.classList.toggle('dz-success');
});

Upvotes: 0

Related Questions