I'm using dropzoneJs to handle file upload. I try to perform an asynchronous operation (via async/await) just before a file starts to be uploaded. So I use the processing event in this way :
function sleep(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
var myDropzone = new Dropzone(document.body,{
url: 'https://someUrl',
paramName: "file",
init: function() {
this.on("processing", async function(file) {
alert("start processing event")
await sleep("5000")
alert("end processing event")
});
}
})
The problem lies in the use of "async await". If I comment the await line, then the "start" and "end" alerts are executed before the file is processed by dropzone. This is the behavior I'm waiting for.
However, if "await" is executed, then the file starts its upload before the await function is finished. So the "end" alert is executed after the file upload has started. This operation is not normal.
Isn't it possible to use "async/await" in dropzone events?