[Zope] Re: uploading images?
Max M
maxm@mxm.dk
Tue, 27 Aug 2002 11:24:42 +0200
Josef Meile wrote:
>I don't know if the html file object has additional properties like content
>type and size.
>
>
No. You would need to do a:
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']
... etc.
The basic idea is that the server need to upload the file before you can see what type of file it is and how big it is. That is caused by the statelessness of the web.
You cannot submit a form and then have the server see the filname/type and size, and then let it upload the file only if it wants to. That part of the html spec could be smarter... but it aint!
regards Max M
"klaatu verata niktu"