Dear forum members,
The problem that I’m facing is that I want to be able to place a user uploaded file in a database I created. My coding skills aren’t that great so I added a photo of the current state of the code and where I’m missing/where I want the piece of code for the problem I have.
Thank you for your time!
Best,
Sander
From the upload results, you need the file location so you can save your document to the collection. Something like this:
let fileLocation = uploadedFile.url;
Then in your toInsert object, you need to add something like this:
"document": fileLocation
Hi Yisrael,
Thank you for the quick reply! it doesn’t seem to be working, I altered it a little bit because it said uploadFile.url wasn’t defined. However the code is still not working 
(please don’t pay attention to the code gore on top)
// API Reference: https://www.wix.com/corvid/reference
// Code Examples: https://www.wix.com/corvid/examples
import wixData from 'wix-data';
//import {sendEmail, sendEmailWithRecipient} from 'backend/email';
$w.onReady(function () {
$w('#uploadButton1').fileType = "Document" ;
$w('#button1').onClick((event) => {
console.log("Clicked");
if ($w('#input1').value.trim().length === 0){
console.log("returned because of input 1");
return;
}
if ($w('#input2').value.trim().length === 0){
console.log("returned because of input 2");
return;
}
if ($w('#input3').value.trim().length === 0){
console.log("returned because of input 3");
return;
}
if ($w('#input4').value.trim().length === 0){
console.log("returned because of input 4");
return;
}
if ($w('#input5').value.trim().length === 0){
console.log("returned because of input 5");
return;
}
let currentItem = $w('#dynamicDataset').getCurrentItem().title;
console.log(currentItem);
let filetype = $w("#uploadButton1").fileType;
console.log(filetype);
$w('#uploadButton1').startUpload()
.then((uploadedFile) => {
let toInsert = {
"title" : $w('#input1').value,
"welkeVacature" : currentItem,
"email" : $w('#input2').value,
"telefoon" : $w('#input3').value,
"opleiding" : $w('#input4').value,
"motivatie" : $w('#input5').value,
"cv" : uploadedFile.url
//"Document Upload" : Function to take the uploaded file and paste it in the database column with this name (pdf/doc document)
}
wixData.insert("solicitatiedataset", toInsert);
})
})
});
@scwaalbers What isn’t working? What is your console output?
Realize that insert() returns a Promise , and the Promise needs to be handled. Or, you need to call insert prefixed with await .
If you’re not sure about the upload, see the Upload Preloader example to see how to upload a file.