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.
This is an old post from last year and you are better suited adding a new post with a link to refer to this post.
As for your issue, the upload button is working fine as shown on this test site for another forum user.
https://givemeawhisky.wixsite.com/onchangetest
The first page is the tutorial from Wix here.
https://support.wix.com/en/article/wix-code-using-the-upload-button-with-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.
Code used.
$w.onReady(function () { }); export function button1_click(event) { if($w("#uploadButton1").value.length > 0) { $w("#text1").text = `Uploading ${$w("#uploadButton1").value[0].name}`; $w("#uploadButton1").startUpload() .then( (uploadedFile) => { $w("#text1").text = "Upload successful"; $w("#image1").src = uploadedFile.url; }) .catch( (uploadError) => { $w("#text1").text = "File upload error"; console.log(`Error: ${uploadError.errorCode}`); console.log(uploadError.errorDescription); }); } else { $w("#text1").text = "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.
It has been like that since 2017!
In the Editor, select the upload button and click Manage Upload Button. Then click Go to File.
https://www.wix.com/corvid/forum/community-discussion/location-of-uploaded-images
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.
You can read more about it in the API Reference itself.
https://www.wix.com/corvid/reference/$w.UploadButton.html
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.") } } );
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...
VERY bizarre...should have checked my site again prior to posting...mine is now working also! Glad it is fixed...frustrated that it was fixed "magically".
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.
I am experiencing the same issue. Anyone from Wix out there? I am dead in the water and phone support just punts on the issue.
If a file gets uploaded at all this is what happens
Anyone from wix here? The website is not working due to this issue. This is urgent