I think the bst way is to use a combined method. Mimetype will tell you if a user mis-uploaded something that you don't support - it's also good at catching all sorts of extension variants (.jpg .jpeg .JPG etc) and also at grouping them into a category (like archives, videos, images, regardless if png, gif, jpg or other). Running through PIL, imagemagic or similar tools is more heavy so it's always a good idea to do it as a second step. Note that identifying with 'file' or similar doesn't always help you if the files are damaged.
On Mar 18, 4:03 pm, Kacper Krupa <[email protected]> wrote: > yes, but it guesses by file extension :) > > On 18 Mar, 16:00, AchipA <[email protected]> wrote: > > > Not web2py, but generic python: > > > import mimetypes > > mimetypes.guess_type(filename) > > > On Mar 18, 9:05 am, Michal Jursa <[email protected]> wrote: > > > > Is it possible to get mime-type of the uploaded object in some web2py > > > manner? It would be better to work with mime-type then some letters in > > > filename I think. > > > > Mike alias Plysak :) > > > > mdipierro wrote: > > > > class IS_GIF: > > > > def __init__(self,em): self.em=em > > > > def __call__(self,value): > > > > if value and value.filename[-4:].lower()!='.gif': > > > > return (value,self.em) > > > > return (value,None) > > > > > db.table.field.requires=IS_GIF() > > > > > On Mar 17, 7:45 pm, TheDude <[email protected]> wrote: > > > >> How would I only allow gif, png or jpeg images to be uploaded? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "web2py Web Framework" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/web2py?hl=en -~----------~----~----~----~------~----~------~--~---

