Upload "document" to selected entry in a data collection

I have a user profile page, where the user can update their personal informations like name, email, living address ,etc.
(Although it is achievable using button on wix, but I would like to try through coding.)
I also added document input button called “#uploadButton1”, and this is the issue I want to solve here.

First of all, here is what I’m trying to do : (I wrote a code below)

  1. Click upload(submit) button on the page
  2. Upload (or store?) file on #uploadButton1
  3. assign file in #uploadButton1 on “register”
  4. Find the entry from the data collection that matches to the user updating info.
  5. set the file stored in #uploadButton1 to the field called “registration”, in the data collection
  6. Update the data collection with new document from #uploadButton1

Here is my problem :
Because I set $w(‘#uploadButton1’) as a “value”,
so in the data collection, it stores the text data of name and file size…
how can I select " document file " that is stored in $w(‘#uploadButton1’)??

It would be very nice if anyone could answer this!
Thank you very much in advance.

//Step 1
export function update_click(event, $w) {

**//Step 2** 
$w('#uploadButton1').startUpload(); 

**//Step 3** 

let register = $w(‘#uploadButton1’).value; //This is the document
let values;
const saId = $w(‘#saId’).text;

**//Step 4** 
wixData.query("SalesAgent") 
    .eq("_id", saId) 
    .find()  
    .then((results) => { 
       
       **//Step 5** 
        values = results.items[0]; //old record 

        //Updating old record in code, it includes the _id field 
        values.registration = register; 

       
       **//Step 6** 
      //update only "value" field, but send all previous field as well 
       wixData.update("SalesAgent", values)    
          .then((results2) => { 
             **let**  item2 = results2;                        
             **const**  alertSuc = $w('#succMsg').show(); 
             $w("#sadb").refresh(); 
             console.log( "UPDATED"); 
          }) 
          . **catch** ((err) => { 
             **let**  errorMsg = err; 
          }); 
          console.log(values); 
  }); 

}

Hello Caud,

Here is a tutorial on how to upload files with code and an upload button.

Here is more information on the upload button element.

Hope this helps,
Majd

Hello Majd,
Thank you very much for your response!

I gave a try but no luck so far.
I have an idea for the solution but not sure few things.

In a code, I typed "$w(‘#uploadButton1’). value ".
To assign the uploaded document to the Filed from data collection.
Instead, can I change (.value) to something else?

Take boolean for example, we write ($w(‘#checkbox’).checked) to assign value.
Are there specific value name for document?

thank you

Yuki

Hello Caud,

Try this video and tell me if things work out: Uploading Images into your Wix Database Collection - Wix Code - Wix My Website Tutorial - YouTube