javascriptes6-promisedropzone.js

Is it possible for Dropzone to wait for a promise to resolve before processing a file?


I am using the latest version of Dropzone (currently v6) and I unable to find a way to make Dropzone wait for a promise to resolve before it starts processing a dropped file.

On the Dropzone's init function I have the following:

init: function () {
    this.on("addedfile", someAsyncMethod);
    this.on("processing", file => {
        console.log("It always enters here before 'someAsyncMethod' promise resolves!");
    });
}

Here is the someAsyncMethod code:

const someAsyncMethod = async () => {
    const url = "https://my-service/api/some-method";
    const result = await fetch(url);
    // do some stuff here with the result
}

No matter what, the event handler for processing alway starts before the on addedfile mehod handler resolves... Is it possible to make Dropzone wait for the onadded handler promise to resolve before it moves on to process the fil added to the queue?


Solution

  • Consider setting the autoProcessQueue option to false. As per the documentation:

    If you have the option autoProcessQueue set to true then the queue is immediately processed, after a file is dropped or an upload finished, by calling.processQueue() which checks how many files are currently uploading, and if it’s less than options.parallelUploads, .processFile(file) is called.

    If you set autoProcessQueue to false, then .processQueue() is never called implicitly. This means that you have to call it yourself when you want to upload all files currently queued.

    This should allow you to invoke processing after someAsyncMethod completes.