Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Upload order with Dropzone.js

I am using Dropzone.js and my PHP script to upload files to my server. I am noticing that they don't exactly upload in the order I select them. For example, say I have 1.jpg, 2.jpg, 3.jpg, 4.jpg & 5.jpg.

They are uploaded in the order the server receives them the fastest. So it could be uploaded like 4, 2, 5, 3, 1.

My PHP script also inserts the file into a database, which is why ordering is important. I couldn't find a config option to upload in order, but I am thinking I might be able to step through the queue and upload them in order that way rather than letting dropzone handle the queue.

like image 799
Ronnie Avatar asked Oct 19 '22 16:10

Ronnie


1 Answers

parallelUploads set to 1 should help, but is a pretty big slow down depending on how many files/size of files to be uploaded.

To get back parallelUploads, but have control over the order, you can pass a FileID back as the response from your upload url, and that can be read on dropzone's success event...

dropzoneObject.on("success", function (file, response) {
    // Requires a hidden field named FileIDs to exist in your previewTemplate.
    $(file.previewElement)
        .find("input[name='FileIDs']")
        .val(response);
});

And after all uploads complete (queuecomplete event), you can post back FileIDs in the order that you want.

like image 150
Sully Avatar answered Oct 22 '22 07:10

Sully