Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dropzone max file size exceeded event

I am using dropzone in my form for image upload. I would like to show an alert message and remove the file added when the user chooses a file above the configured limit. Here is my configuration:

Dropzone.options.myDropzone = { 
      paramName: 'file',
      url: "http://someurl",
      clickable: true,
      enqueueForUpload: true,
      autoProcessQueue: false,
      uploadMultiple: true,
      parallelUploads: 5,
      maxFiles: 1,
      maxFilesize: .06,
      maxThumbnailFilesize: .06,
      acceptedMimeTypes: 'image/*',
      addRemoveLinks: true,
      dictDefaultMessage: 'Drag your images here',
      init: function() {
           console.log('init');
           this.on("maxfilesexceeded", function(file){
                alert("No more files please!");
                this.removeFile(file);
            });

    }
};

I tried to register a listener for 'maxfilesizeexceeded' event, but it didnt fire. I would like to take similar action as for 'maxfilesexceeded'. Is this possible?

like image 448
AVM Avatar asked Dec 02 '22 14:12

AVM


1 Answers

I have just tried it out on my script using the Error event. This way I get an Error Message and the File gets removed again. Is this what you are looking for?

    this.on("error", function(file, message) { 
                alert(message);
                this.removeFile(file); 
    });
like image 105
Luka Avatar answered Dec 09 '22 21:12

Luka