I have a form on my website through which users can upload files. It has both single-upload and multi-upload buttons. I managed to define uploaded files types and numbers with and properties, but couldn’t find in a Velo API how to limit the size of uploaded files.
Is there a way to do that?
1 Like
You can use the onCustomValidation() function to test for file size and other file attributes. You can then accept or reject based on your validation criterial.
Thank you Yisrael for the link, it seems to be just what I need, but I also have a syntax issue here. Could you please tell how it should look like? I tried this one, but after I pick a file and trigger validation function (before file’s uploading process) I get a <File[0] is undefined> console message, though I see no error warning in a code pannel. Should I use ‘value’ somehow or something else… Sorry, I’m new to code nuances.
$w("#uploadButton1").onCustomValidation( (value, reject) => {
if(File[0].size > 1) { reject("File size exceeds 1") ; }
else { console.log('File size:', File[0].size) }
})
Well, you didn’t really pick a file since File is undefined in your onCustomValidation() function.
What you want to do is get the array of files from the button value, and then check each one for validity. Something like this:
$w("#uploadButton1").onCustomValidation((value,reject)=>{
let files = $w('#uploadButton1').value;
files.forEach((file) => {
console.log(file.size);
// check file.size here
});
})
Now it works! You really saved me, thank you so much ! 