Insert a photo to an existing data collection

I have an existing data collection (New users).

After a few days, the user asked to upload an image using a form that includes 2 fields: “email” and “uploads a picture.”

How do I update this image in the appropriate row (the row with his email) in the existing data collection?
(The key value is the user’s email)

  1. I need to search in the data collection for the right email
  2. then, insert the photo to the column “Photo” in this specific row
    What is the right code for that?
  • Users don’t sign up to the website, so I ask them to re-enter their email to know who they are

Thanks!!

Hi,

It is not considered a good practice to allow users to manually edit information in the way you described.
See more below
https://support.wix.com/en/article/preparing-your-wix-site-for-the-gdpr
https://support.wix.com/en/article/corvid-security-considerations

Regardless, it can be achieved as follows:

let imageUrl = 'www.photourl.com/image.jpeg'; //url from upload component
wixData.query('collectionName').eq('email', 'user@mail.com').find().then((res)=> { //find the item
if (res.length) { //if item found, attach the file to the relevant item
let newItem = res.items[0];
    newItem.imageUrl = imageUrl;
    wixData.update('collectionName', newItem) 
}
})