Hello there,
I have been trying for a couple of days now to upload multiple photos from an input form with multiple uploadbuttons to a datacollection.
I want to have the photos in one row of the datacollection. Since it is a member area i also want to automaticly have the member name in that row so i can identify later who uploaded which photos. So far i got:
- just using wixforms and connecting it to db: I can upload multiple photos but i cant get the user name to insert.
- using wixcode: i can upload multiple photos but each photo is inserted in a seperate row.
Any ideas how to get that problem solved?
Can i chain multiple .startUpload ?
Can i get the username to be inserted when i just use the forms?
Is there a workaround where I can use a dummy db and insert all into one db?
Below is my code so far which adds the pictures in different rows.
Thank you,
Jakob
export function button1_click(event) {
//Add your code for this event here: submit button should save all the information in database
let lastName;
let firstName;
let fullName;
//gets user id and compares it with members db..then it gets the name out of memebrs db
wixData.query("Members/PrivateMembersData").eq("_id", wixUsers.currentUser.id).find().then( (results) => {
// Getting the name of the member
fullName = results.items[0].lastName;
//gets the input of the textboxes
let type = $w("#dropdown1").value;
let brand = $w("#textBox1").value;
let description = $w("#textBox2").value;
let condition = $w("#textBox3").value;
let image1 = $w("#uploadButton1").value;
//Upload image 1
if($w("#uploadButton1").value.length > 0) {
$w("#uploadButton1").startUpload($w("#uploadButton1").buttonLabel = "Uploading")
.then((uploadedFile) => {
$w("#uploadButton1").buttonLabel = "Finished";
let toInsert = {
"title": type,
'user':fullName,
'brand' : brand,
'condition':condition,
'description': description,
"image1": uploadedFile.url};
wixData.insert("ConsignedItemsDB",toInsert);
})
.catch( (uploadError) => {
$w("#uploadButton1").buttonLabel = "File upload error";
console.log(`Error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
});
}
else {
("#uploadButton1").buttonLabel = "Select File";
}
//Upload image 2
if($w("#uploadButton2").value.length > 0) {
$w("#uploadButton2").startUpload($w("#uploadButton2").buttonLabel = "Uploading")
.then((uploadedFile) => {
$w("#uploadButton2").buttonLabel = "Finished";
let toInsert = {
"title": type,
'user':fullName,
'brand' : brand,
'condition':condition,
'description': description,
"image2": uploadedFile.url};
wixData.insert("ConsignedItemsDB",toInsert);
})
.catch( (uploadError) => {
$w("#uploadButton2").buttonLabel = "File upload error";
console.log(`Error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
});
}
else {
("#uploadButton2").buttonLabel = "Select File";
}
.catch((err) => {
let errorMsg = err;
});
}