How requires validations OR logic

23 views
Skip to first unread message

Federico Ferraro

unread,
Oct 13, 2016, 8:40:43 PM10/13/16
to web...@googlegroups.com
How validate if upload field is IS_IMAGE or pdf document ?

Try upload pdf document and validate with :

Alumnos.dsalud.requires = [IS_EMPTY_OR(IS_LENGTH(1048576, 1024,error_message=error_img_size)),
IS_EMPTY_OR(IS_IMAGE(extensions='png','jpeg','gif','pdf'),error_message=error_img_tipo)),                   IS_EMPTY_OR(IS_UPLOAD_FILENAME(extension='pdf',error_message=error_img_tipo))]

but error , IS_IMAGE() validator.
 
Thanks .. 

-- 

Anthony

unread,
Oct 13, 2016, 9:42:50 PM10/13/16
to web2py-users
IS_IMAGE(extensions='png','jpeg','gif','pdf')

should be:

IS_IMAGE(extensions=['png','jpeg','gif','pdf'])

Anyway, if you are using IS_IMAGE only to check the file extensions, then just use IS_UPLOAD_FILENAME, which will allow you to check for all the image extensions as well as pdf in a single validator (the only additional feature of IS_IMAGE is to specify a maximum width and height of the image, but you are not using that). Note, the "extension" argument of IS_UPLOAD_FILENAME can be a regex, so you can do r'png|jpg|gif|pdf'.

Anthony
Reply all
Reply to author
Forward
0 new messages