@yisrael-wix
import wixData from 'wix-data';//to work with the collection you need to import this field
export function button1_click(event) {
for (var x = 0; x <= 3; x++) {//for 4 upload buttons the maximum index is 3
if ($w("#uploadButton" + x).value.length > 0) {
$w("#text67").text = Uploading ${$w("#uploadButton"+x).value[0].name};
$w("#uploadButton" + x).startUpload()
.then((uploadedFile) => {
let toInsert = {//myImage is the field key for your images column in the collection
"gallery": uploadedFile.url
};
wixData.insert("locations", toInsert)//myCollection is name of the collection to where the images are added
.then((results) => {
$w("#text67").text = "Upload successful"; //see item below
})
.catch((err) => {
let errorMsg = err;
});
})
.catch((uploadError) => {
$w("#text67").text = "File upload error";
console.log(Error: ${uploadError.errorCode});
console.log(uploadError.errorDescription);
});
} else {
$w("#text67").text = "Please choose a pic to upload.";
}
}
}