On 11/7/06, Sanjay <[EMAIL PROTECTED]> wrote: > > > > Being unable to know how do I get the size of a file being uploaded, > > while using FileField. Needing help. > > 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... >
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 --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

