Upload Video to Pro Gallery

I would like to upload video and image to pro gallery and then store gallery to database. However, I found some problems when uploading video. The video cannot be shown in gallery (photo 1 and 2) and the database (photo 3) cannot show the video item (no.2). Please advise how to solve this problem, the code for uploading video to gallery and storing gallery to database is shown below for your reference.


let workvideo = [];
export async function uploadButton11_change(event) {
 //Add your code for this event here: 
 let greenFlag = false;
 let file = $w('#uploadButton11').value;
 if (file.length > 0) {
 let response = await $w('#uploadButton11').startUpload($w('#uploadButton11').buttonLabel = 'Uploading ...');
        greenFlag = response;
 if (greenFlag) {
            workvideo.push(response.url);
            greenFlag = false;
            console.log(workvideo, file[0].name);
            $w('#uploadButton11').buttonLabel = 'Add another video'
            $w('#text18').expand();
            $w('#text18').text = `Done, Uploaded ${file[0].name}`;
            $w('#gallery1').expand();
 let uploadfileurl = response.url;
 let items = $w("#gallery1").items;
            items.push({
 "src": uploadfileurl,
 "description": "",
 "title": ""
            });
            console.log(uploadfileurl);
            $w("#gallery1").items = items;
        }
    }
}

export function button1_click(event) {
 //Add your code for this event here: 
    $w("#dataset1").onReady(() => {
        $w("#dataset1").setFieldValues({
 "gallery": $w('#gallery1').items,
        });
    });
}

Hi! This might be the Wix side’s problem as they are updating the editor. Make shore you have two upload buttons: 1. for uploading images 2. for uploading videos. Make shore you change the upload button settings. Also, you can’t store both your photos and videos in the same bit of your database as they are different.
Is this what you were talking about? Or is this not your problem?
~Hope this helps!~
Arthur :grinning:

Thanks for the reply. The photos can be shown, but videos cannot after clicking upload button without reloading the page. Is your code only used for repeater? I did not use repeater in this case. Thanks.

1 Like

I am sorry but I don’t think I can help you. Check out my updated reply in case you havn’t done it wet.

Oh, I thought I can use media gallery to store both photos and videos in database.

Thanks.

Hi :raised_hand_with_fingers_splayed:

You’re passing a new title as a parameter to the startUpload() function, which doesn’t accept a parameter, also, you’re not passing the result of the upload process to the next function.

$w('#uploadButton11').startUpload().then((uploadedFile) => {

})

Read more about the upload process using the link above.

1 Like

It’s currently possible to do that, I have it working on the link below:
https://www.alunosustentavel.com/item/Aprender-Alem%C3%A3o-%C3%A9-F%C3%A1cil

The gallery isn’t connected to a database it only connected with code.