thanks
sanjay
I am a novice in web apps, and need some suggestions on this. Should I
go more specific, presenting the sample code, pl let me know...
thaks a lot
sanjay
Have you inspected what you get with widgets.FileField + either of
validators.FieldStorageUploadConverter or validators.FileUploadKeeper (you can
read the docs for these validators at the formencode package)?
Also take a look at cgi.FieldStorage since it is the base for all this (you
don't need to use it directly, but the docs will point you there).
I believe that *IF* the browser informs the size of the message it will be
inside some dictionary and not available as a property on its own... But I
never used that information for anything...
--
Jorge Godoy <jgo...@gmail.com>
Let's say, for example, your file upload field on your form is called
'upload'. Your controller method should have an `upload` parameter
which is, due to the wonders of CherryPy, a cgi.FieldStorage object.
[code]
filename = upload.filename
mime_type = upload.type
file_handle = upload.file
import os
file_size = os.path.getsize(upload.file.name)
[/code]
This will give you `file_size` which will be the size of the file in
bytes. Divide by the appropriate power of 1024 to get it into Kb, Mb,
etc.
Lee
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
While trying "file_size = os.path.getsize(upload.file.name)," I get
Exception: StringIO instance has no attribute 'name'.
Seeing that upload has an attribute "length," I tried that too, but got
-1.
The code below worked, but I don't know whether it is the best way:
data = upload.file.read()
file_size = len(data)
sanjay
This way is probably the best:
upload.file.seek(0, 2)
file_size = upload.file.tell()
upload.file.seek(0)
-bob
sanjay