<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000066">
<font size="-1"><font face="Verdana">I think I get it, except...<br>
<br>
What's the meaning of 1<<20, I'm not familar with that operator.
How would I adjust it for different sizes? <br>
<br>
... as I instantly regret blowing-off bit operators, as "something I
wont need"...<br>
<br>
-Jon<br>
</font></font><br>
Tino Wildenhain wrote:
<blockquote cite="mid1130271617.23228.65.camel@Andrea.peacock.de"
type="cite">
<pre wrap="">Am Dienstag, den 25.10.2005, 14:43 -0400 schrieb Jonathan Cyr:
</pre>
<blockquote type="cite">
<pre wrap="">Hello,
Does a FileUpload object have a get_size() method?
I'd like to limit the size of an uploaded file before commiting it to
the ZODB. I've been Googling for a while. Is it handled differently on
a FileUpload object.
I'm planning to process with a Python Script.
Could someone point me in the right direction?
</pre>
</blockquote>
<pre wrap=""><!---->
The fileupload object is simply a file. (can be cStringIO,
can be tempfile - depending on size)
Best is to do so:
maxsize=1<<20 # 1MB
fu=context.REQUEST.get('fileupload')
fu.seek(maxsize)
if fu.read(1):
raise OverflowError("File too big!") # or something like that
fu.seek(0) # rewind to start
filefolder.manage_addFile(...)
This avoids loading the whole file into memory to find out.
HTH
Tino
_______________________________________________
Zope maillist - <a class="moz-txt-link-abbreviated" href="mailto:Zope@zope.org">Zope@zope.org</a>
<a class="moz-txt-link-freetext" href="http://mail.zope.org/mailman/listinfo/zope">http://mail.zope.org/mailman/listinfo/zope</a>
** No cross posts or HTML encoding! **
(Related lists -
<a class="moz-txt-link-freetext" href="http://mail.zope.org/mailman/listinfo/zope-announce">http://mail.zope.org/mailman/listinfo/zope-announce</a>
<a class="moz-txt-link-freetext" href="http://mail.zope.org/mailman/listinfo/zope-dev">http://mail.zope.org/mailman/listinfo/zope-dev</a> )
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
Jonathan Cyr
<a class="moz-txt-link-abbreviated" href="mailto:cyrj@cyr.info">cyrj@cyr.info</a></pre>
</body>
</html>