Check file size before upload process

94 views
Skip to first unread message

lesssugar

unread,
Jan 26, 2014, 2:33:00 PM1/26/14
to
I'm using IS_LENGTH in my model to validate file size of uploaded image:

IS_LENGTH(2097152, 1, error_message='Max image size: 2MB')

However, the size is being checked after the file's been uploaded, which is not very user friendly when it comes to files larger than 2MB. How can I first validate the file size and then - if it's lower than 2MB - proceed with upload? Can it be done with Python or do I need JS for this?

Massimo Di Pierro

unread,
Jan 26, 2014, 3:38:39 PM1/26/14
to web...@googlegroups.com
You cannot check before it is uploaded. If you use apache or nginx, then can check and block large uploads, but you would get a web server error, not a web2py error.

William Chen

unread,
Mar 10, 2015, 10:39:02 AM3/10/15
to web...@googlegroups.com
I believe you can use 'onvalidation' to check the file size before upload. 

Reply all
Reply to author
Forward
0 new messages