Save Image to Database

Hello, what I am trying to do is save the image in a collection database

  1. upload the image
  2. the uploaded image to be stored in the database

Do not know why the uploaded image is not stored in the database

This is one of the many codes I have tried but without success

$w.onReady(function () {

{console.log("READY")}

    $w('#dataset1').onReady(()=>{
        $w('#button78').onClick(()=>{       

            $w("#uploadButton8").startUpload()
             .then((uploadedFile) => {
                 $w("#image121").src = uploadedFile.url;
                 
                $w("#dataset1").save().
                then(()=>{
                    console.log("the image is being saved ", uploadedFile)
                    $w("#dataset1").setFieldValues({
                        "logofoto":  uploadedFile
                    });
        
                })
                .catch((err)=>{
                    let errMsg = err; console.log(errMsg)});        
                });

            $w('#dataset1').onAfterSave((uploadedFile)=>{
                console.log("The image was saved", upl

Photo

Try this one…

$w.onReady(function () {console.log("Page-READY");
    $w('#dataset1').onReady(()=>{
        $w('#button78').onClick(()=>{console.log("Button --> #button78 clicked");
            $w("#uploadButton8").startUpload()
            .then((uploadedFiles) => {console.log("Uploaded-File-Data: ", uploadedFiles)
                $w("#image121").src = uploadedFiles.url;
                    
                $w("#dataset1").setFieldValues({"logofoto":  uploadedFiles.url}); //--> Field-Type of --> "logofoto" must be an image.
                $w("#dataset1").save();   
            })
            .catch((err)=>{let errMsg = err; console.log(errMsg)});});
        });
    });

    $w('#dataset1').onAfterSave((uploadedFiles)=>{console.log("The image " + uploadedFiles.url + " was saved !!!");
});

@russian-dima You are the best thank you very much for your help . :kissing_heart:

@qlirim-qh1

Check if your DATAFIELD-ID → logofoto <— is correct !?
Rename your buttons corresponding to the CODE-IDs.

const DATASET = "#dataset1";

$w.onReady(function () {console.log("Page-READY");
    $w(DATASET).onReady(()=>{
        
        $w('#uploadButton8').onChange(()=>{
            console.log("Value of Upload-Button changed!");
            $w("#uploadButton8").startUpload()
            .then((uploadedFiles) => {
                console.log("Uploaded-File-Data: ", uploadedFiles)
                $w("#image121").src = uploadedFiles.url; 
                console.log("Preview-Image loaded!")
            })
            .catch((err)=>{let errMsg = err; console.log(errMsg)});});
        });

        $w('#btnSave').onClick(()=>{console.log("Save-Button clicked.");
            $w(DATASET).setFieldValues({"logofoto": uploadedFiles.url});
            $w(DATASET).save();
        });    
    $w(DATASET).onAfterSave((uploadedFiles)=>{console.log("The image " + uploadedFiles.url + " has been saved !!!");});
});

Did already work ? xD
Second version should be better → place it as BEST-NASWER instead of first one (if i am right).

@russian-dima Your code worked very well some small things make it wrong but they were fixed // / thank you very muuuch :smiley: