To upload and image using wix upload button and show the image inside an image box, we must use upload button onChange() event.
For example, we have an upload button to upload profile picture
Here is the code for the upload button onChange() event
//extract url from uploaded file and change image in the imagebox
export function uploadPicBtn_change(event) {
if (event.target.value.length > 0) {
$w("#uploadPicBtn").startUpload()
.then((uploadedFile) => {
$w('#contactImage').src = uploadedFile.url;
})
.catch((uploadError) => {
console.log(`Error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
});
}
}
Enjoy!! 😎😎😎