DropZone event handler not firing corrctly

The event handlers from the fileDropZone don't work amazingly. When uploading a few small files, the event handler (On file uploaded) works fine. When uploading 6 or 7 bigger files, the event handler files before the state of the fileDropZone has updated its value. I have this script which is currently on the on file upload event (The aim is to upload a list of uploaded files to a database table on the retoolDB)

console.log("Uploaded event fired: " + fileDropzone1.value.length + " files processed");
await fileDropzone1.value.forEach(async f => {
await files_AddNew.trigger({
additionalScope: {
file_id: f.fileId,
friendly_name: f.name,
file_size: f.sizeBytes
}
});

This works fine if only a few small files are uploaded. I even tried adding a do loop to try and not fire the event until the state had updated the value, but now it doesn't seem to do anything at all:

do {
if(fileDropzone1.value.length > 0) {
console.log("Uploaded event fired: " + fileDropzone1.value.length + " files processed");
await fileDropzone1.value.forEach(async f => {
await files_AddNew.trigger({
additionalScope: {
file_id: f.fileId,
friendly_name: f.name,
file_size: f.sizeBytes
}
});
await window.resetQuery(files_GetFiles);
console.log("Uploaded event finished");
});
break;
}
}
while (fileDropzone1.value.length == 0);

Any ideas? It would be amazing if the retool storage queries could accept additionalData much like the other queries, then I could handle the uploading of the documents myself

Edit - i've added a debounce time which now works, but not ideal as if even bigger files are uploaded, it may take longer. Ideally, the event would only fire once the state of the dropzone has updated, but it seems to be doing this beforehand or asynchronously.

Hi @FloodMatt,

How large are the files you are uploading?

I tested out console logging the count of files as an event handler on the drop zone component and it worked decently well for me. These files were not very large so I am guessing you are experiencing some type of race conditions as the component runs code to save the file data into the component's state for temporary storage before the upload query runs.

I agree it would be nice for retool storage queries to accept additionalData. Do you have any examples of other queries in Retool that do accept additional metadata/params on file attachments?