I have two questions:
A. Can a user upload multiple images in a database and if yes how?
in my case i want the
user to be able to upload at least one or more images in the field "product images" by clicking the upload image button and selecting multiple images or/and by clicking the button and uploading one image at a time.
B. I want the images the user uploaded to be displayed in a gallery. I know that you can connect images to galleries but the images displayed will be one image from each row, i want for one row to link all the images e.g.
Hello
A) You can upload images and show on you gallery by getting the value uploaded, then inseerting it to your database, and lastly refreshing the gallery dataset. the following code is an example of how to do that:
export function submitButton_click(event, $w) { if ($w("#uploadButton").value.length > 0) { $w("#uploadButton").startUpload() .then( (uploadedFile) => { let toInsert = { "url": uploadedFile.url }; wixData.insert("gallery", toInsert) .then( (results) => { let item = results; }).then(()=>{ $w("#gallerydataset").refresh(); }); }) .catch( (uploadError) => { console.log(`File upload error: ${uploadError.errorCode}`); console.log(uploadError.errorDescription); } ); } }
B) you can do that using code by queering the collection, then pushing the image sources into an aray, and set the gallery items to that array. here's a code example:
let galleryArr = [] wixData.query("myCollection") .eq('title', 'gfbhf') .find() .then((results) => { // get the item (row) and make an array const items = results.items[0]; const objToArr = Object.values(items); objToArr.forEach((link, i) => { if (link === null) { return; } else if (link.toString().startsWith("image")) { // to only push images galleryArr.push({ 'src': link }); } }); $w('#gallery1').items = galleryArr }) .catch((error) => { let errorMsg = error.message; let code = error.code; });
Here's some useful links you can check:
- Wix-data insert()
- WixDataQuery (eq, find,...)
- Gallery Items
Best!
Massa
I have created a blog website like this one but I need to upload multiple pictures and PDF, how can I do that?
You Can Only Upload 1 image at a Time? Really? That kills my whole project If I cant use Galleries
If I have a Media Gallery Field in my Database
Can I allow the users to select and upload multiple images from the front-end?
Right now I can only select 1 image when clicking the Upload Button