Dropzone: cannot trigger 'removedFile' event

Created on 13 May 2015  路  15Comments  路  Source: dropzone/dropzone

in my js file, I have set up something like this:

$(document).ready(function(){

  Dropzone.autoDiscover = false;

  var dropzone = new Dropzone (".dropzone", {
    maxFilesize: 256, // Set the maximum file size to 256 MB
    paramName: "document[attachment]", // Rails expects the file upload to be something like model[field_name]
    addRemoveLinks: true // Don't show remove links on dropzone itself.
  });

  dropzone.on("removedFile", function(file){
    alert('remove triggered');
  });

  dropzone.on("addedFile", function(file){
    alert('add triggered');
  });

  dropzone.on("success", function(file){
    alert('success triggered');
  });
});

I could get he success event, however I cannot get removedFile event when I delete the file from drop zone. addedFile event cannnot be triggered as well even the file has been uploaded successfully to my server.

Is there anything I miss here? Thanks in advance.

Most helpful comment

hi! You write "removedFile" and "addedFile" is error, they should is "removedfile" and "addedfile",
but you can only see event "success" and "addedfile" , not see "removedfile" , you can set autoProcessQueue: false
follow is my test demo

Dropzone.autoDiscover = false;

      var dropzone = new Dropzone ("#mydropzone", {
        maxFilesize: 256, // Set the maximum file size to 256 MB
        paramName: "document[attachment]", // Rails expects the file upload to be something like model[field_name]
        autoProcessQueue: false,
        addRemoveLinks: true // Don't show remove links on dropzone itself.
      });

      dropzone.on("removedfile", function(file){
        alert('remove triggered');
      });

      dropzone.on("addedfile", function(file){
        alert('add triggered');
      });

      dropzone.on("success", function(file){
        alert('success triggered');
      });

I delete $(document).ready(function(){ ...});锛宐ecause it isn't necessary

All 15 comments

hi! You write "removedFile" and "addedFile" is error, they should is "removedfile" and "addedfile",
but you can only see event "success" and "addedfile" , not see "removedfile" , you can set autoProcessQueue: false
follow is my test demo

Dropzone.autoDiscover = false;

      var dropzone = new Dropzone ("#mydropzone", {
        maxFilesize: 256, // Set the maximum file size to 256 MB
        paramName: "document[attachment]", // Rails expects the file upload to be something like model[field_name]
        autoProcessQueue: false,
        addRemoveLinks: true // Don't show remove links on dropzone itself.
      });

      dropzone.on("removedfile", function(file){
        alert('remove triggered');
      });

      dropzone.on("addedfile", function(file){
        alert('add triggered');
      });

      dropzone.on("success", function(file){
        alert('success triggered');
      });

I delete $(document).ready(function(){ ...});锛宐ecause it isn't necessary

@wxb thanks a lot, it works!

Sorry to bring up another question: after uploading using dropzone, I saved the file into the database. when the removedfile event triggered, I also want to delete it from the database. How I can get the saved file id from the file param, so I can make an AJAX call to server to delete the db record?

@anklos
event:success:The file has been uploaded successfully. Gets the server response as second argument. (This event was called finished previously)

 dropzone.on("success", function(file, id){
        var file_serve_id = id;
      });

get file id from server response when a file upload successful

thanks so much!

@wxb Just realize that from your test code, I can get addedfile event, but not success event.

Tried to get the id from the addedfile event, but it was undefined. (dropzone.on("addedfile", function(file, id))

@anklos
The addedfile event have only a argument: file, but success event can set the server response as second argument. so if your code is dropzone.on("addedfile", function(file, id). it's error, because it has one argument:file

@wxb yep. The reason I tried that is because I cannot get success event after file upload, so I cannot the the id.

@anklos
Your server code should return the id,
example: php
you should write

// get $id from database
 echo $id ;

If you don't mind, I'd like to see your code

@anklos
sorry, I got it wrong, because my English is poor
Do you mean to say: success event code not execute when file upload?

@wxb no worries. yes.

success event was not triggered after file uploaded successfully.

@anklos
I have to see all of your code, Otherwise, I don't know why success event was not triggered

@wxb I just copied your demo code. removedfile and addedfile events could be triggered, except success event. quite strange.

@wxb can you see the success event by running your demo code?

@anklos
It's my fault, I update my demo, you can see success event, I am just modifying an attribute:
autoProcessQueue: false, -> autoProcessQueue: true,. if you don't know what it is? you can study https://github.com/enyo/dropzone/wiki/Upload-all-files-with-a-button
in this case,you can click button to upload, so you will see the success event ; but I forgot to set the button in my demo. so you do not see this success event.

@wxb yep that works! Thanks so much!!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

m00nk picture m00nk  路  29Comments

dhardtke picture dhardtke  路  15Comments

luisyq picture luisyq  路  36Comments

pedrocunha picture pedrocunha  路  18Comments

mPisano picture mPisano  路  18Comments