Hi all,
I've looked in the forum but didn't find the answer for my issue.
I'm working on a form where members can upload a file (document) with related fields (Title, description, category, etc.) into a database. I have a button to submit the data, and I'm using code to do that (hard to explain now why I'm using code instead of the inbuilt connection options...).
My problem is, that every field gets into the database using the below code, except the document file... As much as I understand the code, the startUpload should be working...
In the below function "uploadButton1" is my upload button, it is connected to the right db and field (document type).
export function SubmButtClick(event, $w) {
$w("#uploadButton1").startUpload()
.then( (uploadedFile) => {
let url = uploadedFile.url;
} )
.catch( (uploadError) => {
let errCode = uploadError.errorCode; // 7751
let errDesc = uploadError.errorDescription; // "Error description"
} );
let data2insert = {
"category": $w("#dropdown1").value,
"subCategory": $w("#dropdown2").value,
"title": $w("#input1").value,
"description": $w("#textBox1").value,
"cena": $w("#input2").value,
};
wixData.insert("Uploaded_Documents", data2insert)
.then((results) => {
let item = results;
})
.catch((err) => {
let errorMsg = err;
});
}
I tried to solve it with a workaround as to let my submit button to actually submit that document using database collection connection (the text fields are not connected to the db because I'm using code to insert those), but this way the document is uploaded into a separate row than the text fields from the form...
Also, if I just use the code to insert it like: "document": $w("#uploadButton1").value within the "Let" then after it shows some kind of "JS Object" in that field in the db, and I only have the option to convert the field to Document type, and there's no file in the field after...
Thanks for any advice!
![](https://static.wixstatic.com/media/a27d24_5a025083176b41be8e808f3ad6632546~mv2.png/v1/fill/w_63,h_41,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_5a025083176b41be8e808f3ad6632546~mv2.png)
![](https://static.wixstatic.com/media/a27d24_5fb2ae383933407784d5a8ecaef06409~mv2.png/v1/fill/w_49,h_7,al_c,q_85,usm_0.66_1.00_0.01,blur_2,enc_auto/a27d24_5fb2ae383933407784d5a8ecaef06409~mv2.png)
Roi, it's working, thanks a lot! I didn't realize the data2insert has to be inside the ".then" part.
Hi,
Disconnect the upload button from the DB,
Rearrange the submit function:
export function SubmButtClick(event, $w) { $w("#uploadButton1").startUpload() .then( (uploadedFile) => { let url = uploadedFile.url; // Place here the insert method let data2insert = { "category": $w("#dropdown1").value, "subCategory": $w("#dropdown2").value, "title": $w("#input1").value, "description": $w("#textBox1").value, "cena": $w("#input2").value, "document": url // <-- the url of the file you just uploaded }; wixData.insert("Uploaded_Documents", data2insert) }) .catch( (uploadError) => { let errCode = uploadError.errorCode; // 7751 let errDesc = uploadError.errorDescription; // "Error description" }) .then((results) => { let item = results; }) .catch((err) => { let errorMsg = err; }); }
Please Update in your progress.
Good luck!
Roi.