Cell value type is JS Object - Upload button

Hi Guys

For various reasons, I need to code an upload button instead of connecting it through the UI. I’ve used the code in this article (Velo Tutorial: Using the Upload Button with Code | Help Center | Wix.com) with no success…

I keep getitng the error message in the db saying ‘Cell value type is JS Object. Change to document’

I’ve checked permissions, column type (document), etc. but it doesn’t seem to work… Can anybody tell me what I’m doing wrong?

My code is as follows:

export function button1_click_1(event, $w) {
if($w(“#uploadButton”).value.length > 0) {
$w(“#uploadButton”).startUpload()
.catch( (uploadError) => {
console.log(Error: ${uploadError.errorCode});
console.log(uploadError.errorDescription);
});
}
}

i also have the same issue please come to help up
thanks a lot for you help

I am now having the exact same issue. Did anyone figure this out? Would love to know the solution!

looking for a solution to this as well! if anyone can help that would be appreciated

Hi Sean

I can’t remember to be honest, but since that post, I’ve done many successful builds with the upload button. Would you mind sharing your code so I can take a look?

import wixUsers from ‘wix-users’;

import wixData from ‘wix-data’;

import wixLocation from ‘wix-location’;

$w.onReady( function () {

let user = wixUsers.currentUser;

let isLoggedIn = user.loggedIn; // true

user.getEmail() 

    .then((email) => { 

let userEmail = email;

        $w("#emailText").value = userEmail; 

        $w("#createProfileButton").onClick(() => { 

let toInsert = {

“firstName”: $w(“#firstName”).value,

“lastName”: $w(“#lastName”).value,

“email”: $w(“#emailText”).value,

“phoneNumber”: $w(“#phone”).value,

“cv”: $w(“#uploadCV”).startUpload()
.then( (uploadedFile) => {

  } ) 

}

           wixData.insert("Talent", toInsert) 

                .then(() => { 

                    wixLocation.to("/account/profile-page"); 

                }) 


       }); 

    }); 

});

thanks Tiaan, please see code below. when you upload a document, the document shows in the visitors upload folder, but in the database it under the “cv” column it shows {} and the error message . “Cell value type is JS Object. Change to Document.” instead of having the document

@Sean Huynh

So there are a couple of things we learnt over time that might help to explain it a bit better to you.

The first thing you need to do is create a global variable, call it ‘image’ or something like that. Then you need to place your upload button first and call the upload, wait for the upload to complete and in the .then() section of the upload button, assign the uploadedFile.url to the image variable, eg:

image = uploadedFile.url

Then, also in between then .then(())=>{ } curly brackets, run the rest of your insert function.

If you follow this logic, you should be good to go.

Good luck!
Tiaan

thanks Tiaan. I’m pretty new, so not sure how to define a global variable… can you assist?