Update member using updateMember( ) - wix-members-backend

I’m implementing a custom member area, and since all Wix apps use member data like name and profile photo from the default Wix Members data collection, I need to ensure member information is updated in both the default and custom members data collections.

To do this, I’m using the updateMember() function from wix-members-backend, which works well for most fields—except the profile photo. The Wix Members Backend API doesn’t explain how to update the profile photo specifically, but I was able to find the required format by checking the output of the currentMember() function through console.log()

below is the current code

$w("#professionalUpdateButton").onClick(async () => {
        const professionalMembersDataset = $w("#professionalMembersDataset");

        try {
            // Save the dataset which automatically updates the fields connected to the dataset
            await professionalMembersDataset.save();

            // Retrieve the updated data from the dataset
            const updatedData = professionalMembersDataset.getCurrentItem();

            // Prepare memberData with values from the saved dataset item
            const memberData = {
                contactDetails: {
                    firstName: updatedData.firstName,
                    lastName: updatedData.lastName,
                },
                profile: {
                    nickname: updatedData.nickname,
                    profilePhoto: {
                      url: updatedData.photo,
                    }
                },
            };

            // Get the current member ID from the dataset
            const memberId = updatedData._id;

            // Call the backend function to update Wix Members system data
            const response = await myUpdateMemberFunction(memberId, memberData);

            // Show success message if update was successful
            if (response && response.status === 200) {
                console.log(
                    "Member data updated successfully:",
                    response.updatedMember
                );
                $w("#updateSuccessMessage").text = "Your content has been updated.";
                $w("#updateSuccessMessage").show();
                setTimeout(() => {
                    $w("#updateSuccessMessage").hide();
                }, 5000);
            } else {
                throw new Error("Failed to update member in Wix Members system.");
            }
        } catch (err) {
            console.error("Error updating member data:", err);
            $w("#updateErrorMessage").text =
                "An error occurred while updating member data.";
            $w("#updateErrorMessage").show();
            setTimeout(() => {
                $w("#updateErrorMessage").hide();
            }, 5000);
        }
    });

As you can see, I’m setting profilePhoto.url to the field containing the photo. However, when I try to reference the field that holds the uploaded profile image, such as:

•	updatedData.photo.src
•	updatedData.photo.url
•	updatedData.photo.fileUrl

… none of these seem to work. Manually inserting a URL like “https://example.image.png” works fine, so I believe it’s an issue with accessing the correct URL format for the uploaded image.

If anyone has insights or a solution, I’d greatly appreciate the help

In Wix, retrieving the URL of an uploaded image can be tricky because the dataset stores uploaded file information as an object rather than a direct URL. This means you have to navigate the structure of the object returned in your dataset to extract the actual URL.
The method getImageUrl() from wix-media-backend can help convert this reference into a usable URL for updating the profile.

Thank you for your prompt response. I have made some discoveries regarding the issues I encountered:

1.	The function getImageUrl() is not present in the wix-media-backend; however, I found that getFileInfo() is available.
2.	The URL fetched using getFileInfo() does not work for updating the profile photo in the member area. The URL format “wix:image://v1 …” does not lead to the actual stored image.
3.	After several attempts, I discovered that I needed to retrieve the image name and construct the URL in the format: https://static.wixstatic.com/media/${fileName}.

This solution is now working for me, but I would like to confirm whether https://static.wixstatic.com/media/ is a stable location that will remain unchanged in the future.

Thank you for your assistance!