November 8th, 2004, 03:35 PM
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.
data = file.read()
fileSize = len(data)
November 8th, 2004, 04:04 PM
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?
November 9th, 2004, 08:58 AM
I passed the uploaded file to a python script
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.
size = os.path.getsize(file)
"TypeError: coercing to Unicode: need string or buffer, instance found..."
November 9th, 2004, 04:24 PM
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,
Last edited by netytan; November 9th, 2004 at 04:27 PM.