[Tutor] Determine Filetype
admin at gg-lab.net
admin at gg-lab.net
Sat Sep 19 17:20:33 CEST 2009
Ops, i have another question, it seems very simple.
I want to check the extension of an uploaded file. So i've created a
list with allowed extensions:
enabled_ext = ['gif', 'jpeg', 'png', 'bmp', 'tiff']
How can i create a simple if that check if the file ext (file_ext) is
in the list?
I've searched in the python tutorial, but have not been able to find
any example that uses an if statement combined with a list.
Thankyou again
2009/9/19 admin at gg-lab.net <admin at gg-lab.net>:
> Hi All,
>
> the solution was in the link i've posted before. If i use:
>
> type = imghdr.what('img.test', image.data)
>
> The imghdr modules ignore the filename (first argument) and takes the
> second as a data stream assumed to contain the filetype.
>
> The solution only works for images, but that's what i need. I think
> that right now is not possible to generally determine the mimetype for
> all types of files on GAE, because some libraries are missing. Anyway,
> i'll send a mail to the gae mailing list, and if find a solution i'll
> post it here.
>
> Thankyou all guys.
>
> 2009/9/19 Sander Sweers <sander.sweers at gmail.com>:
>> On Fri, 2009-09-18 at 16:48 -0400, Kent Johnson wrote:
>>> > So, the __init__.py file of the GAE evinronment's ctypes library is
>>> > broken, as it's importing from a package that doesn't exist. Right?
>>>
>>> Probably ctypes is not supported in GAE, that would be a pretty big
>>> security hole.
>>
>> There is a pure python implementation on pypi [1]. It states it is in
>> alpha and missing some features. Never used it myself though...
>>
>> Greets
>> Sander
>>
>> [1] http://pypi.python.org/pypi/pymagic/0.1
>>
>> _______________________________________________
>> Tutor maillist - Tutor at python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
More information about the Tutor
mailing list