Image Upload to Specific Item in Dataset

Greetings,

I fully understand how to update specific items in my dataset, but how do I update an image in a specific item?

Problem details:

I’m using a submit button to update my selected dataset item. I know how to code the submit button so that it will also submit an image file selected from my computer using an upload input button. But I can’t figure out how to upload that image into my dataset for a specific item. I can do it with everything else. Just not images.

Really looking forward to some insight on this one.

Hey David

Ive seen a couple of different situations like this.

  1. followed a guide where you pick image and click button to upload it which also saves it to the dataset (making an empty entry with only an image)

  2. Not actually setting the connection to the dataset for the upload but instead of a preview image which uploads nothing.

  3. Trying to combine it with something else (in my latest case it was member dataset) forcing me to manually look up the dataset entry after a submit and add the image by itself using a save.
    Hope these ideas might give a bit of guidance, if not ill advice a preview link to the page or using the code snippet so we might be able to see what is missing.

best regards
Claes

Okay, man. And thank you. Here are the details for what I have:

On clicking my submit button (“#essavebutton”), I want the file I’ve selected to upload to replace the image file for a specific item in my dataset (selected by drop-down). If no file is selected, I want no change to occur for the image field in that item. The second part of my code works beautifully (the no-change part), but the upload part is not replacing the image file for the item selected.

Anything “e_xxx” is a global variable that is changed according to user input. My thinking is that upon upload, the new image’s “src” would be used to change my “e_flier” global variable src. Not sure why this isn’t working. I checked my Wix folders to see if my test image did indeed upload, but it hadn’t. I believe this is part of the problem. I am hoping you can help.

Here’s my code:

export function essavebutton_click(event) {
 if ($w("#esimagebtn").value.length > 0) {
      $w("#esimagebtn").startUpload()
       .then( (uploadedFile) => {
         e_flier = uploadedFile.url;
      })
      let toEvents = {
          "title": e_title,
           "_id": e_id,
           "flier": e_flier,
           "status": e_status,
           "eventTitle": e_eventtitle,
           "month": e_month,
           "day": e_day,
           "hr": e_hr,
           "mn": e_mn,
           "ampm": e_ampm,
           "zone": e_zone,
           "notes": e_notes
      }; 
      wixData.update("HLLES", toEvents);
 } else {
      let toEvents = {
           "title": e_title,
           "_id": e_id,
           "flier": e_flier,
           "status": e_status,
           "eventTitle": e_eventtitle,
           "month": e_month,
           "day": e_day,
           "hr": e_hr,
           "mn": e_mn,
           "ampm": e_ampm,
           "zone": e_zone,
           "notes": e_notes
      };
      wixData.update("HLLES", toEvents);
}

Looking forward to your insight, my man.
Thank you.

Hello?

Hey David
So sorry, we had a code review Friday and your post was lost in the constant notifications from there.

I would suggest first you try Console.log( $w ( “#esimagebtn” ). value ) inside that if statement and outside of it
I believe the if statement is not valid.

If the statement is actually run and look correct (value makes sense) when you have uploaded something. I think this might be one of the situations where wix does not allow your upload with button, but instead you need to input a $w(“image”) that gets set with the value from the upload button, and updates the database with that image src instead.

When ever you work with Wix media is quickly becomes a bit of a mess because of their unique method to media management.

Hope this makes some level of sense.

best regards
Claes

Thank you. I’ll try that. I thought you guys forgot about me – lol. I didn’t get a notification for some reason, and I’m swamped in a side project, presently.

But I will definitely test this out and let you know. This is the last part of my project. It’s for a comprehensive gaming schedule I’m making. But I’ll certainly need to have the image “replace” sorted for my slideshow mods.

Thanks again, man.