luca72 schrieb:
> if i ask for the filename i do this name = brano.filename and is ok
> 
> but for ask the size i have try with brano.fileze and brano.size but i
> get:
> AttributeError, name
> 
> How i have to do for know the file size

What gave you the idea that file fields have a 'size' attribute?
Uploaded files are passed to your controller as cgi.FieldStorage objects
with a 'filename' and a 'file' attribute. The latter refers to a
file-like object, which has the usual methods for reading (read,
readlines, etc.).

If you want to know the file size, you have to read the file and count
the bytes. Here's an adapted example from the documentation of the
standard library module 'cgi':

MAX_READ = 1024 * 32
if fileitem.file:
    # It's an uploaded file; count bytes
    bytecount= 0
    while 1:
        data = fileitem.file.read(MAX_READ)
        if not data: break
        bytecount += len(data)

Here's the code for a minmal controller that handles a file, upload,
counts the file size and show the attributes of the file object:

http://paste.turbogears.org/paste/8496


Chris

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to