Hi,
On testing the new code for the GuestPhoto-Gallery I recognized a strange behavior of the uploadButton functionality.
In the beginning I’ve separated the code for the two parts choose a file / upload the file. The upload was executed by a button with an onclick event.
Then I decided to integrate the function execution for the upload in the ChooseFile function. After that I got several times an error “no file to upload” although the filename was indicated at the UploadButton!
Did anybody have the same behavior? Have did you solve it? Or is there a bug in my code?
Here’s my code:
export function butChooseFile_change() {
if($w("#butChooseFile").value.length > 0) {
let files = $w('#butChooseFile').value;
if (files[0].size > 512000) {
$w("#textUpload").text = 'La taille du fichier est trop grande, choisissez un autre';
return;
}
$w('#ddYear').focus();
// Here I've integrated the execution of the photoUpload()
photoUpload();
}
else {
$w("#textUpload").text = 'Choisissez une photo pour télécharger ...';
}
}
/* Execution of the photoUpload() by clicking the Upload Button everything was ok with this execution
export function buttonUploadFile_click(event) {
photoUpload();
}
*/
// The upload of the choosen photo
export async function photoUpload() {
$w("#textUpload").text = `Télécharger ${$w("#butChooseFile").value[0].name}`;
await $w("#butChooseFile").startUpload()
.then( (uploadedFile) => {
if (uploadedFile.width > 1400 || uploadedFile.height > 1050) {
$w("#textUpload").text = 'Le format de la photo n\'est pas valide, choisissez une autre';
dataComplete.image = false;
return;
}
$w("#textUpload").text = "Téléchargement terminé";
dataComplete.image = $w('#butChooseFile').valid;
imageUrl = uploadedFile.url;
$w('#imgProof').src = uploadedFile.url;
})
.catch( (uploadError) => {
console.log(uploadError.errorDescription);
});
}
Two important information:
- My internet connection is based on satellite and is really slow
- If I set a delay of 6 seconds before executing the photoUpload(), it works!
But it works also with the button, even if I click the uploadButton within a second!
Hope somebody can help!