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.
1 Like
Este es un problema que no lo explican en estos forum de wixcode, el boton cargar imagen a veces funciona y otras veces no.
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.
Si de hecho. He intentado hablar con ellos pero no me responden. Aparentemente cuando se le quita la casilla de requerido funciona mejor. Pero sigue siendo algo que a veces presenta problemas. Si tienes alguna noticia al respecto por favor hazmela saber
export function uploadButton_change(event) {
if ($w(“#uploadButton”).value.length > 0) {
setTimeout(() => { $w(“#uploadButton”).startUpload().then(uploadedFile => {
$w(“#image30”).src = uploadedFile.url;
});
}, 1200);
}
}
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
the code I uploaded is different and is a single button, dictate the English
Please post your reply in english and not spanish so that everybody can read and understand it.
Especially if you mention something that should be picked up on by somebody within the Wix Team etc.
“This is a problem that is not explained in these wixcode forum, the image upload button sometimes works and sometimes it does not.”
How long ago did you ask Wix? Allow at least 24hrs and not 1hr to respond!
Did you ask Wix Support as if it is to do with code, they will send you here anyway.
Also, don’t forget time differences and when Wix teams are actually working themselves.
If you were talking about this post here note that it is over a year old now, so you would be much better making your own new post now.
https://www.wix.com/corvid/forum/community-discussion/error-on-upload-button