Forbid uploaded image file names that have spaces in them

40 views
Skip to first unread message

Wayne Shirley

unread,
Feb 26, 2023, 8:51:33 AM2/26/23
to web2py-users
I need to prevent a user from being able to upload an image file that has spaces in the file name.

Eventually the filename will be included in a url as part of a CMS.

Is there a built-in function in web2py that does this?

How to go about this?

Thanks.

Massimiliano

unread,
Feb 26, 2023, 10:03:08 AM2/26/23
to web...@googlegroups.com
Maybe you can manage the thing server side.
Take a look here: 

--
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
---
You received this message because you are subscribed to the Google Groups "web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to web2py+un...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/web2py/c4419907-4957-4326-9323-6772284266aen%40googlegroups.com.
--
Massimiliano

Leonel Câmara

unread,
Feb 28, 2023, 1:44:39 PM2/28/23
to web2py-users
Slugs are indeed a good idea, but if you really want to force no spaces you can use a regex with IS_FILE.

Something like requires=IS_FILE(filename=re.compile('^[^\s]+$'))

Note that you probably still want to use IS_SLUG because this will not prevent people from using \, /, ?, .. and other stuff that you probably don't want in URLs
Reply all
Reply to author
Forward
0 new messages