Does .reset() on uploadButtons work properly?

Hi, I spotted an error regarding my upload buttons - reset function is not working in Live site (in Editor Preview it’s working well).
Any solution to this issue pls?

export function uploadButton1_change(event) {
let mySizeLimit = 4194304;
let files = $w("#uploadButton1").value;
let fileSize = files[0].size;
if (fileSize > mySizeLimit) {
$w("#uploadButton1").reset(); //upload button is not reset in Live site, though text317 (code line below) expands as required
$w("#text317").expand();
}
}

Thx!

If something works in PREVIEW but not in LIVE-MODE, this has mainly the following reasons…

  1. Data is not synced. Check if you did a syncronisation between LIVE and PREVIEW-DB.

  2. You do not have the right DB-PERMISSIONS. Check your DB-Permisssion-Setup.

  3. Async-Await-problem–> check if your code-structure is right. Does your code have synchronous parts?
    Add ASYNC-AWAIT, to let your code work synchronous.

Hi @russian-dima , thanks for your hints…

Ad1 - the code asks to reset the uploadButton, therefore there’s no interaction with the DB (yet) and therefore the issue has no root in Sandbox vs. Live…

Ad2 - checked today, even lifted all DB permissions to check if here’s the issue, but this did not make any difference

Ad3 - so I’ve ended up with ASYNC-AWAIT. Honestly, I’m not familiar with this - is there an easy way you could advise me on how to rewrite the code using ASYNC-AWAIT?

Still, I’m not sure about it - I did some research also in Velo API reference and the guide that’s provided there on .reset() is well aligned with my code I think… https://www.wix.com/velo/reference/$w/uploadbutton/reset It’s a simple IF statement, nothing more…

Thanks for any advice! :slight_smile:

@rusty I think you are trying to generate a VALIDATION, which will recognoze if the file-size is ok or not.

I tried it with ASYNC-AWAIT, but it did not work, perhaps i did an mistake…

export async function btnUP0_change(event) {
   let mySizeLimit = 100000; console.log("Size-Limit: ", mySizeLimit);
   let files = await $w("#btnUP0").value; console.log(files);
   let fileSize = await files[0].size; console.log("File-Size: ", fileSize);
   if (fileSize > mySizeLimit) {
       $w("#btnUP0").reset();
       $w("#text1").text="Selected file-size exceeded !!!";
       console.log("Selected file-size exceeded !!!");
   }
   else {$w("#text1").text="File accepted !!!"; console.log("File accepted !!!")}
}

I don’t know why the await-version did not work, but this one definetely will work…

export function btnUP0_change(event) {
   let files = $w("#btnUP0").value;    console.log(files);
   let mySizeLimit = 100000;           console.log("Size-Limit: ", mySizeLimit);
   let fileSize = files[0].size;       console.log("File-Size: ", fileSize);
   
   if (fileSize > mySizeLimit) {
        setTimeout(()=>{$w("#btnUP0").reset();},100)
        console.log("Selected file-size exceeded !!!")
   }
   else {console.log("File accepted !!!")}
}

It has a similar behaviour like with the value of inputs or dropdowns, where you need a certain delay-time, till the value is setted-up —> setTimeout(()=>{},100);

You can see the last code-version with the —> setTimeout-function in action on the following site…

https://www.media-junkie.com/multi-upload

Attention! The example, works only for the first UPLOAD-BUTTON (green one).


All the other buttons do not have this VALIDATION-function (because it is just for testing and showing you how it could work).

Just the first UPLOAD-Button do NOT-ACCEPT files bigger than —> 100KB.

Choose for example a pic which has less than 100KB and try to upload. Than choose a file that has more than 100KB and try to upload again. What happens?

And YES! What you see is my old version of a multi-uploader (workaround) :rofl:

Also, do not forget to take a look into the CONSOLE-LOGS !
Or you take a look onto the INFO-TEXT on the bottom of the example-site.

Here the new link for the example…
https://www.media-junkie.com/tutorial-muploader-free

@russian-dima thanks! I’ll try to go with setting the timeout, on a blank page it worked fine, now I just have to incorporate it to my code :slight_smile:

Is the fileSize bigger than mySizeLimit? You could put a console.log(“Error, file too big”) in the if statement to see if it’s working.