0

I want to limit the number of selectable files when user want to upload with dropzone to maximum of 5 files each time but the user can upload more than that in total. so a user can choose up to 5 files each time, but after selecting the first 5 files, he can choose another 5 files and so on..

so my ideal case is like this:

step 1: user selects and uploads file a1, a2, a3 // success
step 2: user selects and uploads file a11, a12, a13, a14, a15, a16 // these 6 files should not get uploaded

I found getUploadingFiles().length here. but that way, file a11-a16 are still uploaded. if I use removeAll(), then a1-3 will also get deleted. I need it so that only a11-a16 will get cancelled but a1-3 is still safe. can it be done?

my code looks like this:

mydz.on('sendingmultiple', function(file) {
  if (mydz.getUploadingFiles().length > 5) {
    mydz.emit('error', file, 'max selected file is 5!');
  }
});

mydz.on('error', function(file, errMsg, xhr) {
  mydz.removeFile(file);
  $('#form_msg').html(errMsg);
});

EDIT it turns out that when I call getAcceptedFiles().length in the sendingmultiple event will give the number of files selected. so I can use this instead.

dapidmini
  • 1,490
  • 2
  • 23
  • 46
  • Check if this answer is helpful https://stackoverflow.com/a/41297698/8079581 – matrixersp Oct 08 '20 at 07:40
  • Does this help? https://stackoverflow.com/questions/18048825/how-to-limit-the-number-of-dropzone-js-files-uploaded – gkulshrestha Oct 08 '20 at 07:41
  • @matrixersp unfortunately no, `maxFiles` will limit the total number of the files that can be uploaded at that time. I don't want to limit the total number of files, just the number of files selected each time.. – dapidmini Oct 08 '20 at 07:45

0 Answers0