How to wait for trigger in onSuccess?

Hi guys, I have this code:

for (let i = 0; i < fileInput1.value.length; i++) {
  await upload.trigger({
    additionalScope: {
      fileBase64: fileInput1.value[i].base64Data,
      fileName: "testname" + [i] + ".pdf",
    onSuccess: function (data) {
        additionalScope: {
          dateiname: data.url,

I am once triggering the query upload, and once the query insert. However I want the loop to wait for the query insert to finish before it starts over, how do I achieve that?

put await before it just like you have before upload.trigger

I thought about the same but unfortunately that leads to this error:

await is only valid in async functions and the top level bodies of modules