Hi,
I’m trying to create a file-upload page using code. I’ve created an upload button, and I’m now trying to make a “submit” button to grab the file and save it in a collection. I’m using “startUpload()” to upload the file, but then the code keeps on running without waiting for it to actually upload, so it reaches the point where it saves it to the collection before there’s anything to actually save. I’ve tried using “await” but it’s not recognized. Is there a way to tell the code to wait for the file to upload?
Thanks
Use this, it works for me.
export function uploadImage() {
//Upload function by wixshow.com
if ($w("#uploadButton1").value.length > 0) { // user chose a file
console.log(`Uploading '${$w("#uploadButton1").value[0].name}'`);
$w("#uploadButton1").startUpload()
.then( (uploadedFile) => {
console.log("Upload successful. File is available here:");
$w("#image10").src = uploadedFile.url;
console.log(uploadedFile.url);
// Save the url to the data collection
} )
.catch( (uploadError) => {
console.log(`File upload error: ${uploadError.errorCode}`);
console.log(uploadError.errorDescription);
} );
}
}
This seems to work, thanks!