Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > check uploaded file's file size?

Reply
Thread Tools

check uploaded file's file size?

 
 
h3m4n
Guest
Posts: n/a
 
      07-08-2006
i have a short script that allows users to upload files, but when i try
to check for a valid filesize (using fileitem) i get '-1' i can't find
information about using filesize anywhere. any ideas?

code:

form = cgi.FieldStorage()
fileitem = form["datafile"]
print str(fileitem.filesize)

-h3m4n

 
Reply With Quote
 
 
 
 
Simon Forman
Guest
Posts: n/a
 
      07-08-2006
h3m4n wrote:
> i have a short script that allows users to upload files, but when i try
> to check for a valid filesize (using fileitem) i get '-1' i can't find
> information about using filesize anywhere. any ideas?
>
> code:
>
> form = cgi.FieldStorage()
> fileitem = form["datafile"]
> print str(fileitem.filesize)
>
> -h3m4n


Try this

fileitem.seek(0, 2) # Seek to the end of the file.
filesize = fileitem.tell() # Get the position of EOF.
fileitem.seek(0) # Reset the file position to the beginning.

If the fileitem is a normal file this should work.


Peace,
~Simon

 
Reply With Quote
 
 
 
 
h3m4n
Guest
Posts: n/a
 
      07-08-2006
> Try this
>
> fileitem.seek(0, 2) # Seek to the end of the file.
> filesize = fileitem.tell() # Get the position of EOF.
> fileitem.seek(0) # Reset the file position to the beginning.


thanks for the info. i just had to change it from fileitem to
fileitem.file, e.g. fileitem.file.seek(0, 2), and it worked fine.

- h3m4n
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Check that uploaded photo is a JPEG Chris Mahoney ASP .Net 3 02-08-2007 08:22 PM
Check if uploaded jpg uses CMYK or RGB pallete?? gt ASP .Net 0 12-03-2003 11:20 AM
virus check uploaded files. rajesh ASP .Net 0 10-29-2003 11:54 PM
Virus check files being uploaded. rajesh ASP .Net 0 10-29-2003 11:53 PM
Virus-Scanning uploaded files uploaded? Matt G ASP .Net 1 08-22-2003 05:44 AM



Advertisments