There is something about marking an upload button as a required field that conflicts with my code to make the image display in an element after uploading. Here is my code that works fine when the upload button is not marked as a required field:
....
$w("#uploadButton1").onChange( (event, $w) => { let files = $w("#uploadButton1").value; let fileSize = files[0].size; if(fileSize < 250000) { $w("#uploadButton1").startUpload() .then( (uploadedFile) => { $w("#image1").src = uploadedFile.url; console.log(uploadedFile.url) }) .catch( (uploadError) => { console.log(`Error: ${uploadError.errorCode}`); console.log(uploadError.errorDescription); }) } else{ wixWindow.openLightbox("FileSize"); $w("#uploadButton1").reset() } });
...
Once I use the editor to mark it as a required field, however, uploading the same file that was working before will throw an error (logged in the debug console as Error code -1, No file to upload). The weird thing is that the data does exist regardless of the error and it gets entered correctly into the database when I hit 'submit' at the end of the form.
What's causing this? Why is there a conflict when the element is a required field vs. when it's not?
edit: forgot to mention that it only happens upon the first instance of uploading. Once I press the upload button again and change the file, it displays correctly.
There is already a Wix Corvid tutorial for showing image for user upload, check it out here.
https://support.wix.com/en/article/wix-code-using-the-upload-button-with-code
please let me know if you have fixed the issue, I am facing the same problem and i have talked to the wix team but they do not respond.
Este es un problema que no lo explican en estos forum de wixcode, el boton cargar imagen a veces funciona y otras veces no.