Hi, I know the question has been asked several times here in the forum, but I can’t find a right answer. I want to upload multiple images via an upload button and store them in my Data collection in the “Media-gallery” field “Images”. Because I search for existing entries of members and then filter the dataset, I have not connected the upload button in the editor with the dataset, but want to solve this by code.
I’m not that good at arrays yet. Probably that’s why I have a wrong coding. Would be very happy about some help.
My code (focus on the " uploadFiles" part) :
let uploadedImages;
$w . onReady ( function () {
$w ( ‘#SubmitReviews’ ). onBeforeSave (() => {
if ( $w ( “#btUploadImages” ). value . length > 0 ) {
$w ( “#btUploadImages” ). label = “Uploading images” ;
console . log ( “Uploading the following files:” )
$w ( “#btUploadImages” ). uploadFiles ()
. then ( ( uploadedFiles ) => {
uploadedImages = uploadedFiles . forEach ( uploadedFile => {
uploadedFile . fileUrl ;
})
console . log ( “Upload successful.” );
} )
. catch ( ( uploadError ) => {
console . log ( "File upload error: " + uploadError . errorCode )
console . log ( uploadError . errorDescription );
} );
}
else { // Site visitor clicked button but didn’t choose a file
console . log ( “Please choose a file to upload.” )
}
} );
} );
export function btSubmit_click ( event ) {
if ( reviewExists === 0 ) {
$w ( "#SubmitReviews" ). add ()
. then (() => {
$w ( '#SubmitReviews' ). setFieldValues ({
images : uploadedImages ,
});
$w ( '#SubmitReviews' ). save ();
})
} **else** {
$w ( '#SubmitReviews' ). setFieldValues ({
images : uploadedImages ,
});
$w ( '#SubmitReviews' ). save ();
}
}