onChange Upload works for few files

I have a form where users upload an image and the image is then displayed as a preview beside the upload button before the form is submitted. The image sometimes gets uploaded and sometimes doesn’t. It seems like it only works for certain images…

Here’s the code:

$w('#uploadButton1').onChange(() => {
 if ($w("#uploadButton1").value.length > 0) {
            $w("#uploadButton1").startUpload()
                .then((uploadedFile) => {
                    $w("#full").src = uploadedFile.url;
                    $w("#half").src = uploadedFile.url;
                    $w("#quater").src = uploadedFile.url;
                    $w('#image20').src = uploadedFile.url;
                    $w('#image30').src = uploadedFile.url;
                    $w('#vectorImage21').hide();
                    $w('#vectorImage22').hide();
                    $w('#fail').hide();
                    $w('#submit').enable();
                    calc();
                })
                
                .catch((uploadError) => {
                    console.log(`Error: ${uploadError.errorCode}`);
                    console.log(uploadError.errorDescription);
                });
        }
    });
});
1 Like

I would like this function to be more reliable. I can’t understand why it works for certain files.

Hi Brett!

Any chance that your upload button is connected via Dataset and uses it to insert the files into the collection? Does the code you posted is the entire code?

If not please share a link to your site so one of us, the Wix Code team, can inspect it and provide you with a solution.

Doron.

Hi Doron. The code I posted is not the entire code. The entire code a few hundred lines. These are the lines that include the functionality of the upload button. The actual button is connected to a Dataset, and now that you mention it, I think it might have stopped working around the time I connected it, but not completely sure. Please let me know what I should do, and if you would like me to post the entire code. @doron-alkalay

Anyone? @doron-alkalay

Hi @brettfranklin2 !

Please share a link to your site so I can inspect it and provide you with a solution. :slight_smile:

Doron.

@doron-alkalay www.brettfranklin2.wixsite.com/website-2

The problem is on the print ad, printed insertion and online ad pages.

Hi @brettfranklin2 !

It seems like in all of the above pages that you mentioned you use on the same elements all of the following three methods:

  1. DataBinding (connection to dataset)
  2. export function uploadbutton1_change (Event handler)
  3. .onChange function directly on the element

Since the dataset is set to write only I believe that its not it, but,
when you use in two different places the same function with different methods and different script - results may be unexpected.

I suggest that you refrain from using 2 & 3 together.

Try to change it and let me know if it worked for you.

Doron.

Is there any other way around it? I’m afraid that I have the print products and digital products under one database so it can be easier to record them in the campaigns area by differentiating them by print and digital products.

Also, I remember this problem was occurring before I connected both forms to the databases. Also, if connecting two forms to one database is the issue, then the online form would work, right? That form is connected to one database and one form. @doron-alkalay

same issue in my form.

Brett Franklin can you fix it?

???

This post is from 2018, so being closed.

This example should suit your needs.
https://support.wix.com/en/article/wix-code-using-the-upload-button-with-code

Please add a new post to the forum if still need help.