英文:
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 always starts before the on addedfile method handler resolves... Is it possible to make Dropzone wait for the onadded handler promise to resolve before it moves on to process the file added to the queue?
英文:
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?
答案1
得分: 1
请考虑将autoProcessQueue
选项设置为false
。根据文档:
如果您将选项
autoProcessQueue
设置为true
,那么队列会在文件被拖放或上传完成后立即处理,通过调用calling.processQueue()
来检查当前正在上传多少个文件,如果小于options.parallelUploads
,则会调用.processFile(file)
。如果将
autoProcessQueue
设置为false
,则不会隐式调用.processQueue()
。这意味着您需要在希望上传当前排队的所有文件时自己调用它。
这应该允许您在someAsyncMethod
完成后调用处理。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论