[Zope] File upload Content type and File size

Paul Erickson erickson@kaivo.com
Mon, 04 Mar 2002 09:24:59 -0700


You can figure out how big an uploaded file is (in a somewhat roundabout 
way) before putting it into the ZODB.

This will test to make sure that it's not an empty file:

<dtml-if expr="new_file.seek(0, 2) or file.tell() > 0">

 <dtml-call "manage_addFile( id=new_ArtNo, file=new_file, title=new_ArtNo)">

</dtml-if>

What it is doing is seeking to the end of the file, then using tell() to 
show the current position in the file.  If tell() is above 0, then you 
know that it's not an empty file.

I haven't tried it, but if you've got some particular maximum in mind, 
you could do this:

<dtml-if expr="new_file.seek(0, 2) or file.tell() > 64000">
  Your file is too big!!
<else>

 <dtml-call "manage_addFile( id=new_ArtNo, file=new_file, title=new_ArtNo)">

</dtml-if>

-Paul


James van der Veen wrote:

>Hi everybody,
>How woyld I be able to let a user upload a file and check the file size and
>content type.
>
>What I would like to do is check the filesize and content type of the file
>before adding it to zope.
>But It would be ok to get this info afterwards so I can immediatly delete
>the file.
>
>I use a form to upload the file.
>Then process the info:
>
><dtml-call "manage_addFile( id=new_ArtNo, file=new_file, title=new_ArtNo
>)">
>this works fine.
>What I thought I had to do next is:
>
><dtml-with new_ArtNo>
><dtml-var get_size>
></dtml-with>
>(still in the same dtml-method)
>
>but I donīt seem to get the property of the new created file but the folder
>it is in and this raises an error.
>I think it does this because if I say:
>
><dtml-with new_ArtNo>
><dtml-var title_or_id>
></dtml-with>
>
>I get the title of the folder.
>
>Can someone tell me how to get the right size of the newly added file.
>
>Sure hope so!
>
>Greetz,
>Sjeems
>
>_______________________________________________
>Zope maillist  -  Zope@zope.org
>http://lists.zope.org/mailman/listinfo/zope
>**   No cross posts or HTML encoding!  **
>(Related lists - 
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>