[Zope] Re: uploading images?

Josef Meile jmeile@hotmail.com
Tue, 27 Aug 2002 12:54:03 +0200


> f = *REQUEST.form['attached_file']*
> fileContent = f.read()
> size = len(fileContent)
>
> import os.path
> head, tail = os.path.splitext(f.filename)
> # is it a legal image file ? We dont want users to upload bmp or excel
files :-/
> isImage = tail in ['.gif', '.jpg', '.jpeg', '.png']
I saw your solution and I think it has a problem. You're assuming that files
have
always an extension, but that's not true. What would happen with the Unix
and
MAC users who are not forced to give the file an extension to know that it's
an
image? I just tested what happened when importing a "bmp", "gif", or "jpg"
without
an extension: Zope knows what kind of file it is. I guess the solution is
closer to this
one:
http://www.zopelabs.com/cookbook/992900431

However, it doesn't say if it's a jpg, gif, bmp, etc. But I guess that
attribute can be
also obtained, for Zope stores something like: image/pjpeg, image/gif,
image/bmp, etc.

I haven't try it because I don't actually need to do that validation, but I
guess
it would be nice.

Greetings,
Josef.