• 2678 views
  • 0 comments
  • loading...

Special type validator

IS_UPLOAD_FILENAME validator checks if the name and extension of a file uploaded through the file input matches the given criteria.

It does not ensure the file type in any way. Returns validation failure if no data was uploaded.









# Check if file has a pdf extension (case insensitive):

requires = IS_UPLOAD_FILENAME(extension='pdf')

#Check if file has a tar.gz extension and name starting with backup:
requires = IS_UPLOAD_FILENAME(filename='backup.*', extension='tar.gz', lastdot=False)

#Check if file has no extension and name matching README (case sensitive):
requires = IS_UPLOAD_FILENAME(filename='^README$', extension='^$', case=0)

Attributes / Arguments

Filename (before dot) regex

requires = IS_UPLOAD_FILENAME(filename='backup.*', ...)

Extension (after dot) regex.

requires = IS_UPLOAD_FILENAME(..., extension='tar.gz')

Which dot should be used as a filename / extension separator: 

                    • True indicates last dot (e.g., "file.tar.gz" will be broken in "file.tar" + "gz") 
      • False means first dot (e.g., "file.tar.gz" will be broken into "file" + "tar.gz").

requires = IS_UPLOAD_FILENAME(..., lastdot=False)

0 means keep the case

1 means transform the string into lowercase (default)
2 means transform the string into uppercase.

requires = IS_UPLOAD_FILENAME(..., case=0)


loading...

Sources / Reference

" Web2py Book"


Comments

loading...

Powered by
Web2py

Hosted on
www.pythonanywhere.com
(affiliated link)