0

I use dropzone.js to upload files to a server. The server then responds with a file id and new filename for deleting purpose.

I found this solution.

Deleting renamed file on server using Dropzone.js

But when I use the uploadMultiple:true option, it sends multiple files in a single request. So I get the same response in all success callbacks, how can I receive the appropriate JSON response in each individual success callback?

Dropzone.options.dropzone1 = {
    paramName: "file",
    uploadMultiple:true,
    success: function( file, response ) {
        //this callback will run twice
        console.log(response) //same response in each callback
    }
}



$ret = array();
array_push($ret,array('id' => $id1,'filename' => $newfilename1));
array_push($ret,array('id' => $id2,'filename' => $newfilename2));
echo json_encode($ret);
Brian K.
  • 416
  • 1
  • 6
  • 15
CL So
  • 3,647
  • 10
  • 51
  • 95

1 Answers1

0

With uploadMultiple: true you are only sending one request (containing two files) to the server. Because you're only sending one request, you would only get one response in return. This is the response that you're seeing in the success callback for each file.

Note: success is called for each file in the queue whereas successmultiple is called once for all files when uploadMultiple: true.

To get one JSON response per file, set uploadMultiple: false (or remove it since it's false by default).

uploadMultiple only tells the Dropzone instance whether or not to stick all the files in a single request. It does not limit the ability to upload multiple files at the same time (they're just done in individual requests per file).

Brian K.
  • 416
  • 1
  • 6
  • 15
  • I set `uploadMultiple: true` because I need use this. Finally I use original filename as array key to response the JSON – CL So Sep 15 '19 at 17:36
  • Yes, I guess in your case you wouldn't necessarily need to have 1 response per file to achieve your goal. I was directly responding to the question you asked in your post. Glad you got it figured out though. – Brian K. Sep 16 '19 at 19:46