Failed setting items: TypeError: Cannot read property 'length' of undefined?

Hi,

I am having an error as: Failed setting items: TypeError: Cannot read property ‘length’ of undefined
when https://100001.onl/ I apply the following code:

import wixData from 'wix-data';

export function uploadButton1_change(event) {
 if($w("#uploadButton1").value.length > 0) {
    $w("#uploadButton1").value[0].name};
    $w("#uploadButton1").startUpload()
      .then( (uploadedFile) => {
           wixData.insert("User-GeneratedContent", uploadedFile).then(() => {
                    $w("#dataset1").refresh();

            })
      })
}

Please help me out to solve the issue!

Thank you

The upload button works in two parts, as noted in the Wix API Reference.
https://www.wix.com/corvid/reference/$w.UploadButton.html
https://support.wix.com/en/article/adding-and-setting-up-an-upload-button

Typical File Upload Scenario
In a typical scenario, the page from which files are uploaded contains an upload button and another element, such as a regular button. The site visitor chooses which file to upload by clicking the upload button and selecting the file in a native file chooser dialog. At that point the file is stored in the upload button’s value property as a File object.

Then the site visitor triggers an event, such as a button click, on the other element. That element’s event handler calls the startUpload() function to perform the actual upload. The upload either succeeds and gives you an UploadedFile object, or fails and gives you an UploadError object.

You can see more in this example here.
https://support.wix.com/en/article/corvid-tutorial-using-the-upload-button-with-code

The value property of the upload button returns an array of File objects, each representing a file the site visitor has chosen to upload. So we check its length to see if this array has at least one item in it, meaning the site visitor has chosen at least one file.

You can save the image to a field in your dataset by connecting it up to the appropriate field and adding a submit button.