10

Im using the dropzone js (http://www.dropzonejs.com/) to upload files but I need to know how many files are currently inside the Dropzone, the user might have deleted some but I need to know if there is at least 1 file before I submit the whole form that the user is filling.

If i use the myDropzone.length it will still count the removed files from the dropzone so if the user adds 2 files and then removes one of them the .length would be = 2 and in that case I would need to know the real length which would be 1 in this particular case

ajeleandro
  • 101
  • 1
  • 1
  • 6

2 Answers2

18

Dropzone provide multiple function to get only accepted, rejected, queued or uploading files.

// To access only accepted files count (answer of question)
myDropzone.getAcceptedFiles().length


// To access all files count
myDropzone.files.length
// To access all rejected files count
myDropzone.getRejectedFiles().length
// To access all queued files count
myDropzone.getQueuedFiles().length
// To access all uploading files count
myDropzone.getUploadingFiles().length

Get from document API here

Camille
  • 2,439
  • 1
  • 14
  • 32
  • I am trying to get a list of the files that are in the Dropzone. How do I access the list of files in the Dropzone? – user1794918 Nov 17 '17 at 11:11
  • 1
    @user1794918 Use `myDropzone.files`. Remove `.lenght` of upper example and you can get file list of every sections – Camille Nov 17 '17 at 15:44
4

"To access all files in the dropzone, use myDropzone.files."

http://www.dropzonejs.com/#dropzone-methods

imjared
  • 19,492
  • 4
  • 49
  • 72
  • 1
    The problem is when the user decides to remove one of the files, then the .length remains the same counting the removed files, so I need to know how many files are there without the removed ones – ajeleandro Oct 28 '16 at 15:55