Try the following:
def PythonScript1(afile=None):
'''
read file info
afile is name of HTML INPUT TAG
HTML FORM AS FOLLOWS
<FORM ACTION="PythonScript1" METHOD="POST"
enctype="multipart/form-data">
<INPUT TYPE="file" NAME="afile">
<INPUT TYPE="submit" VALUE="OK">
</FORM>
NOTE: without [enctype] file will be transerred as string
'''
afile.seek(0,2) #move to end
bytes=afile.tell()
afile.seek(0) #rewind
#optional--converto to KB/MB
megs=bytes / 1048576.0
if megs > 1:
print "%.2f MB" % megs
k=bytes / 1024.0
if k > 1:
print "%d K" % k
print "%d bytes" % bytes
return printed
AnThu Nguyen <Anthu.Nguyen@Sun.COM> wrote:
Hi,
I'm trying to get the size of a file uploaded via an HTML form before
it's written. "context.REQUEST.file" only accesses the file name, not
the content. How do I read the contents? Any help will be much
appreciated.
TIA,
AnThu
_______________________________________________
Zope maillist - Zope@zope.org
http://mail.zope.org/mailman/listinfo/zope
** No cross posts or HTML encoding! **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope-dev )
Do you Yahoo!?
Get on board. You're
invited to try the new Yahoo! Mail Beta.