Code-programmed picture upload by uploadButton isn't displayed and database shows this.

How should I edit my code?

You need to explain your problem. What code? What are you doing? What does your database look like?

Simple pages to look at.

https://support.wix.com/en/article/wix-code-using-the-upload-button-with-code

https://support.wix.com/en/article/adding-and-setting-up-an-upload-button

https://www.wix.com/corvid/reference/$w.UploadButton.html

Hi, if i may jump in the conversation… these links were very useful to solve a part of a problem i am facing.
IN a lightbox i Have an uploadButton and a ‘preview’ image, and i was able to show the chosen image in the preview image using the uploadButton. But now what i want to do is to have the chosen picture stored in a field of my database.
I use this code but it does not work. I think that the .src parameter is not valid but i cannot find a way to access to the ‘real’ content of the preview image and store it in the database postImage field.

  • thumbImage is the ‘preview’ image that loads correctly the picture chosen with uploadButton1
  • userPosts is the database where i want to save the picture
  • postImage is the field of the database where i want to write the image
export function button2_click(event) {
 
if($w("#uploadButton1").value.length > 0) {
$w("#uploadButton1").value[0].name;
    $w("#uploadButton1").startUpload()
      .then( (uploadedFile) => {
        $w("#thumbImage").src = uploadedFile.url;
      })
      .catch( (uploadError) => {
        console.log("File upload error: " + uploadError.errorCode);
        console.log(uploadError.errorDescription);
      });
  } 
 else {
  }
let toInsert = {
postImage: $w('#thumbImage').src,
}

wixData.insert("userPosts", toInsert) 

.then( (results) => {
let item = results; 
console.log("OK")
        }) ; 

}