Code which has been working properly for a couple of months now suddenly stopped working. Isolated the issue to startUpload() which does not upload the file and basically stops the code from running:
if ($w("#uploadButton1").value.length > 0) { // user chose a file
submittedProject.file1Name = $w("#uploadButton1").value[0].name;
await $w("#uploadButton1").startUpload()
.then( (uploadedFile) => {
submittedProject.file1 = uploadedFile.url;
})
}
I haven’t seen examples using ‘await’ for startUpload() but I need it since the page needs to refresh after the upload. In any case it has worked until today and removing ‘await’ does not solve the issue. I haven’t touched the code so nothing has changed on my end. Help? This is urgent.
The issue is solved, but in the most annoying way. By itself.
I discovered that the files were in fact uploaded (if you go to the upload button, press settings and ‘view files’ you’ll see the files) so the issue was in the linking with the uploaded files or rather ‘.then’ after ‘startUpload()’ never executed… but now it does. Nothing changed in the code between working, then not working, and now working. So my guess is a Wix glitch until proven otherwise.
Well the good thing is that it was fixed ‘magically’ for both of us, meaning it was a real issue and now it is resolved. That’s what matters at the end of the day…
It even states that in the Wix Corvid tutorial for it too. https://support.wix.com/en/article/wix-code-using-the-upload-button-with-code
Finally, let’s return to the Editor and find the uploaded file. Select the upload button and click Manage Upload Button . In the Upload Button Settings panel, click Go to File , which opens the images that have been received by your site. There you should see the image you just uploaded.
UploadButton
An upload button enables users to upload files to your site.
Typical File Upload Scenario
In a typical scenario, the page from which files are uploaded contains an upload button and another element, such as a regular button. The user chooses which file to upload by clicking the upload button and selecting the file in a native file chooser dialog. At that point the file is stored in the upload button’s value property as a File object. Then the user triggers an event, such as a button click, on the other element. That element’s event handler calls the startUpload() function to perform the actual upload. The upload either succeeds and gives you an UploadedFile object, or fails and gives you an UploadError object.
Examples
Typical file upload scenario
$w('#myButton').onClick( () => {
if ($w("#myUploadButton").value.length > 0) { // user chose a file
console.log(`Uploading '${$w("#myUploadButton").value[0].name}'`);
$w("#myUploadButton").startUpload()
.then( (uploadedFile) => {
console.log("Upload successful. File is available here:");
console.log(uploadedFile.url);
} )
.catch( (uploadError) => {
console.log(`File upload error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
} );
}
else { // user clicked button but didn't chose a file
console.log("Please choose a file to upload.")
}
} );
did anybody find a solution for this? I have the same problem my upload button used to work then all the sudden it stopped without changing any line of code.
The only thing that I have added is a seperate dataset set to write and a submit button connected to the dataset, so that after the user has chosen their image and uploaded it , they can then submit their images to the dataset after.
You don’t need to have the seperate start upload button to save it to a dataset, you can simply have the upload button and the submit button connected to the dataset.