Re: [Zope] Get uploaded file size

2006-08-03 Thread Dieter Maurer
AnThu Nguyen wrote at 2006-8-2 10:13 -0700:
> ...
>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.

If "context.REQUEST.file" is the file name and not a
"ZPublisher.HTTPRequest.FileUpload" object, then you
are doing something wrong. Either you use an HTTP "GET" request
or you do not use "multipart/formdata" as mime type.

A "FileUpload" object behaves like a file and you can
use the usual way to determine its size.


-- 
Dieter
___
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 )


Re: [Zope] Get uploaded file size

2006-08-02 Thread AnThu Nguyen




Roberto,

This is perfect - exactly what I needed!

Thanks,
AnThu

Roberto Benitez wrote On 08/02/06 01:50 PM,:

  Try the following:
   
  def PythonScript1(afile=None):
    '''
    read file info
    afile is name of HTML INPUT TAG
    HTML FORM AS FOLLOWS
    
    
    
    
    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 <[EMAIL PROTECTED]> 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.



___
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 )


Re: [Zope] Get uploaded file size

2006-08-02 Thread Andreas Jung



--On 2. August 2006 10:13:17 -0700 AnThu Nguyen <[EMAIL PROTECTED]> 
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.



Read the data into a string and determine the length of the string.

-aj


--
ZOPYX Ltd. & Co. KG - Charlottenstr. 37/1 - 72070 Tübingen - Germany
Web: www.zopyx.com - Email: [EMAIL PROTECTED] - Phone +49 - 7071 - 793376
E-Publishing, Python, Zope & Plone development, Consulting


pgp4MHOmysI8f.pgp
Description: PGP signature
___
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 )


[Zope] Get uploaded file size

2006-08-02 Thread AnThu Nguyen

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 )