Re: uploading images?
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.
Josef Meile wrote:
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:
You are right off course! you should use the mimetype info instead of my approach. regards Max M "klaatu verata niktu"
Max M wrote:
You are right off course!
you should use the mimetype info instead of my approach.
OFS/Image.py has a useful function that can guess the filetype of a FileUpload object, I can't, however, remember what it's called... cheers, Chris
participants (3)
-
Chris Withers -
Josef Meile -
Max M