I have a database with about 3000 entries already loaded. These were loaded from a CSV file.
What I need it to insert a Thumbnail image into each record. Each record has a unique ID that I have loaded into the Wix ID field. I have searched for a while and have not found a way to do this other than one at a time, which is totally unfeasible for this many records.
I assume I would have to first upload all these images to my Wix Image Library and then connect each one to their respective database entry.
Thanks
JD
Hi,
My suggestion is to add a button element and create an onClick event.
The code should look similar to this but you need to adapt it to your site:
import wixData from 'wix-data';
export function makeUpload_click(event, $w) { const images = $w('#gallery1').items; images.forEach(image => { uploadImageToDatabaseByTitle(image); }) } function uploadImageToDatabaseByTitle(image) { console.log('log') wixData.query('yourDatabase').eq('imageTitle', image.title).find() .then(results => { const item = results.items[0]; item.imageSrc = image.src; wixData.update('yourDatabase', item) }) .then(() => { console.log('done to upload image') }) .catch(err => { console.log('error: ', err); }) }
Please update in your progress.
Roi.
Yes, the image name will be the same as a database field. For example:
PartNo in database(a text field): 12345
Imagename will be: 12345.jpg
Unfortunately it's not possible to access the media manager using code.
It is possible to upload all images to the media manager, connect it to a galley and get all urls of the images using code.
Unless you have an unique identifier of those images like file name or title that matches to the new entry, It has to be done semi-manually.
Roi.
Roi,
You are not understanding..., Yes, I know I can click plus sign and add the image. I have over 3000 images I need connected to the database. I don't want to do this by clicking + sign, locating image 3000 times. Looking for Wix code to do this.
Ahhh, ok.
Just click on the plus sign and it opens the media manager.
Don't forget to set the type of the field to image.
Roi.
Roi,
What I was asking is HOW to add the uploaded images into the database fields. I know I could upload them to the image library but that does not get them into the database?
Hi,
"I assume I would have to first upload all these images to my Wix Image Library and then connect each one to their respective database entry."
That is correct.
Roi.