store images from a lightbox in the database

I have an existing lightbox with an image gallery (it has been created using the Wix upload functionality). I now want to get the image gallery and store it in a database. I am trying to get the image gallery with the following code in the lightbox page:

$w.onReady( function () {
let images = $w(" #gallery1 ").items;
console.log(images.length); /// returns 0
});

For some reason, this does not work. I am using the same code on a normal page and there it works, so I guess there is something I need to do differently in a lightbox?

You might need to simply pass the data from the lightbox back to the page.

How do I pass data between a page and a lightbox?
When you open a lightbox using the openLightbox() function, you can pass an object containing data to be used in the lightbox. In the lightbox’s code, you call the getContext() function to retrieve the data sent by the openLightbox() function.

When you close the lightbox using the close() function, you can pass an object containing data to be used by the page that opened the lightbox. This data is retrieved from the resolution of the Promise returned by the openLightbox() function.

https://www.wix.com/corvid/reference/wix-window.lightbox.html

the problem is that I have not opened the lightbox programmatically. It was created using Wix functionality. So, when I run the getContext() function I get “undefined” in the console.
Somehow the lightbox is different to a normal page.
It is weird though that I can access text fields without a problem, only the image gallery is not working

Actually, just found the reason why I can’t get the images through code. It’s because it is a Wix Pro Gallery.
Here is the text from the ‘item’ method:

Note

You can only get the items of a Pro Gallery using the items property if you set its items using the items property or connect the gallery to a dataset first. If you set the gallery’s items in the Editor, you are not be able to retrieve them with the items property. This limitation does not apply to standard galleries.

This really sucks. Is there a way this could be rectified or do you have another trick up your sleeve.

Chris

Is there a way to change the Wix Pro Gallery to a normal Slider Gallery. That would solve the problem!

Yes, remember that Wix Pro Gallery is a Wix app and not really suitable for being injected with code as it will have its own code running, so sometimes the Wix app might override your own settings in code etc.

If you want to use a gallery with code, then you are always best to use a normal gallery and not the Wix Pro Gallery app, yes you will lose the additional features from Wix Pro Gallery, however you will have to compromise.

I should have asked at the start if you were using a Wix Pro Gallery as it would have been mentioned much earlier to you, however at least know you know and can correct it for future uses.

You would probably be better and easier just to add a new gallery and start again, unless you want to go through and add all your items through code in a items array if you wanted to stick with the Wix Pro Gallery app option.
https://www.wix.com/corvid/reference/$w.Gallery.html#items

Set the list of items for a gallery

$w("#myGallery").items = [{
  "type": "image",
  "alt": "A beautiful view",
  "title": "A View",
  "src": "wix:image://v1/99bc1c6f66444769b531221214c885ac.jpeg/A%20View.jpeg#originWidth=3264&originHeight=2448"
}, {
  "type": "video",
  "description": "Another beautiful view",
  "title": "Another View",
  "src": "wix:video://v1/80c05f_e2c524db1f264178a8558c92dbf76fb0/_#posterUri=80c05f_e2c524db1f264178a8558c92dbf76fb0f000.jpg&posterWidth=1920&posterHeight=1080"
}];

https://www.wix.com/corvid/reference/$w.Gallery.html
https://www.wix.com/corvid/reference/$w.GalleryItemChangedEvent.html
https://www.wix.com/corvid/reference/$w.GalleryItemClickedEvent.html

my problem is actually that I have like a hundred lighboxes which were created by somebody using Wix functionality (so no programming). Unfortunately, they used Wix Pro Gallery. What I want to do is to get all the galleries from the lightboxes into a database so that I can create a dynamic page instead of the hundred lightboxes.
So, if there is a way to get the gallery out of the Wix Pro Gallery into a database then I’d be keen to know.
Second question is whether there is maybe a way to change a Wix Pro Gallery to a normal Wix gallery using Wix functionality (this would solve the problem, since I could then just use the let images = $w(" #gallery1 ").items; )

If the images aren’t already in a dataset, then they will simply all be in your Media Manager.
So, unfortunately for you, how do I put it gently that you are going to be a busy person?

You can simply put the image URL of the file from the Media Manager into a dataset and use that instead of physically adding the picture to a dataset field.

However, whichever way you go about it, either adding the image URL or adding the image directly, you will unfortunately have to manually get the image downloaded from the Media Manager or simply get the URL of each image.

https://support.wix.com/en/article/downloading-files-from-the-media-manager
https://support.wix.com/en/article/retrieving-the-url-of-an-image

Hopefully the person whoever did your site originally just by using the Wix Editor and no code, well cross fingers that they have a backup folder of all the images so that you don’t have to manually get them all yourself.

If you don’t have backups of your images then you will have to manually get each one I am afraid.

To save you some time, you could hard code each separate gallery once you have the image URL all done, at least that way you won’t have to paste them all into a new dataset.
https://www.wix.com/corvid/reference/$w.Gallery.html#ImageItem

Examples

Set the list of items for a gallery

$w("#myGallery").items = [{
  "type": "image",
  "alt": "A beautiful view",
  "title": "A View",
  "src": "wix:image://v1/99bc1c6f66444769b531221214c885ac.jpeg/A%20View.jpeg#originWidth=3264&originHeight=2448"
}, {
  "type": "video",
  "description": "Another beautiful view",
  "title": "Another View",
  "src": "wix:video://v1/80c05f_e2c524db1f264178a8558c92dbf76fb0/_#posterUri=80c05f_e2c524db1f264178a8558c92dbf76fb0f000.jpg&posterWidth=1920&posterHeight=1080"
}];

Does the lightbox have an url? Or can I somehow get the whole lightbox stored in the database? I guess that every lightbox must have some sort of code that makes it appear. I guess it is in the button that opens the lightbox?!

Have a read of this page about lightbox in gallery urls etc.
https://support.wix.com/en/article/lightbox-appearing-in-site-url

As for lightbox urls, have a look here.
Wix Code Courses - Getting a Lightbox URL

I forgot about this post, see if it helps you to get it sorted.
https://www.wix.com/corvid/forum/community-discussion/getting-all-image-url-s-in-the-media-manager