How to limit the number of dropzone.js files uploaded?

pydanny picture pydanny · Aug 5, 2013 · Viewed 110.5k times · Source

Depending on the use case, how do I constrain the number of files that dropzone.js will allow?

For example, I might need to only allow 1, 2, or 4 files uploaded.

It's not uploadMultiple. Unfortunately, uploadMultiple only applies to the number of files handled per request.

Answer

oneirois picture oneirois · Sep 27, 2013

I achieved this a slightly different way. I just remove the old dropped file any time a new file is added. It acts as overwriting the file which was the user experience I was going for here.

Dropzone.options.myAwesomeDropzone = {
  accept: function(file, done) {
    console.log("uploaded");
    done();
  },
  init: function() {
    this.on("addedfile", function() {
      if (this.files[1]!=null){
        this.removeFile(this.files[0]);
      }
    });
  }
};