You’ve got a form where users can upload files from their computers or smartphones. But you’ve noticed that many of the uploaded files are huge and taking up a lot of storage space. It would be great if you could limit the size of the files users can upload.
For example, we have a job portal where applicants can apply for jobs and upload their resumes. However, we want to prevent them from uploading resume files that take up too much space. So we want to limit them to files that are no bigger than 20MB:
Jenny Martin tried to upload a file that was larger than 20MB. Instead of the form submitting, she received a message letting her know that she needs to upload a smaller file.
Note: This can work for both File and Image fields.
If this your first time creating an app, you'll need to know some basics about adding objects, fields, pages, and views. You can start by watching our "Introducing Knack" video tour and then working through the articles in our Builder Basics section. Other good resources can be found in our designing the database and building pages sections of the knowledge base.
Select the Object with the File Field
In the Data section of the builder, select the object that contains the file field whose size you want to limit. If the file field doesn’t already exist, create a new one.
Open the Field Editor
Click on the gear icon of the file field to open the editor and go to the Validation Rules section.
Add the Validation Rule
Check the “Add field validation rules” box:
For the When part of the rule, select the file field and then the “size is greater than” option. Once that’s selected, you’ll be able to choose the size limit.
For the Message part of the rule, you can enter the custom message you want the user to see.
Your validation rule is now ready and your users will automatically be prompted if they try to upload those larger files.