wixData.update command won't send file to collection


I am trying to save an uploaded document to a collection.

First I get values from the collection and show them on a page. I have no problem with that. Then, besides updating some text fields, I also want to update a field for uploaded files in collection. I have to submit the data with code for some reason. I used the line below for saving uploaded files. When I click the button all the fields are updated, but in collection for the field for uploaded files (of which the field name is ‘document’) it displays this warning: “Cell value type is JS Object.” . It does not save the document.

“files”: $w(‘#uploadButton1’).startUpload()

My whole code for updating the collection is like this:

export function button1_click(event, $w) {
let poz_kod = $w(‘#dropdown1’).value;

let toUpdate = {
“_id”: $w(‘#input1’).value,
“adi”: $w(‘#pozekletxtbox2’).value,
“seviye”: $w(‘#pozekletxtbox3’).value,
“aciklama”: $w(‘#pozekletxtbox4’).value,
“poz”: poz_kod,
“files”: $w(‘#uploadButton1’).startUpload()

wixData.update(“pozisyonlar”, toUpdate)
.then( (results) => {
let item = results;
} )
.catch( (err) => {
let errorMsg = err;
} );

Can you help me please?
Thanks in advance.

Look at the article How to Use the Upload Button with Code . This explains the procedure.

Yisrael hi. Thanks for reply. I tried the way given in the article but trying to save a document like an image is useless, as field type (document) is inconsistent with the file we are trying to save the collection (image). As field type in the collection is document, I think somehow I must use a document type of item but don’t know how to do it :-). For example document items don’t have attribute of “.url” or stg.

Yisrael hello. Using “.link” solved the problem. Thank you.

1 Like