#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    180
    Rep Power
    11

    Getting the size of an uploaded file


    I am having trouble finding the size of an uploaded file. I am using zope so I'm not sure if anyone can help me but I am going to try anyway.

    The uploaded file is passed to a python script when I find the files size using the following method the contents of the file when opened is blank.

    Code:
    data = file.read()
    fileSize = len(data)
    Any suggestions?

    Thanks,
    Laura
  2. #2
  3. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    I don't have much experiance with Zope, but if your using a Python script then can you not just use the os.path.getsize() function?
    programming language development: www.netytan.com Hula

  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2004
    Posts
    180
    Rep Power
    11
    I passed the uploaded file to a python script

    Code:
     import os
    
     def getFileSize(file):
       size = os.path.getsize(file)
       return size
    However, I am receiving an error through the zope side. I know you don't have experience with zope but perhaps the error message will help.

    "TypeError: coercing to Unicode: need string or buffer, instance found..."

    Thank You.
  6. #4
  7. Hello World :)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2003
    Location
    Hull, UK
    Posts
    2,537
    Rep Power
    69
    Mmmm, it looks like your passing a file instance to the os.path.getsize() function instead of the path to the uploaded/stored file on the server.

    If you haven't already, write the uploaded file to your desired location and give os.path.getsize() the path to your file; you might want to save it as a temp file if you dont want to keep the uploaded files.

    Hope this helps,

    Mark.
    Last edited by netytan; November 9th, 2004 at 04:27 PM.
    programming language development: www.netytan.com Hula


IMN logo majestic logo threadwatch logo seochat tools logo