0

I have a functionality for testing out the file size in python server. But after converting file it into Request object (i.e file converted to python object) size mismatched. File size is somewhat smaller than python object. Files are attached from a form in post request.

Is there a way to know correct file size from object in python?

I am using tornado server at backend.

Thanks

igauravsehrawat
  • 3,696
  • 3
  • 33
  • 46
  • 1
    Why do you need to? You can use `os.path.getsize()`. – cdarke Jul 24 '16 at 07:58
  • Of-course but its for file on the disk only, I have files from form converted into Request object, Request file object doesn't match file size on disk? For e.g I am limiting 2MB attachment per file on server but 2MB is more than 2MB on server. – igauravsehrawat Jul 24 '16 at 08:54

1 Answers1

1

Already answered here

# f is a file-like object. 
old_file_position = f.tell()
f.seek(0, os.SEEK_END)
size = f.tell()
f.seek(old_file_position, os.SEEK_SET)
Community
  • 1
  • 1
Billyoyo
  • 11
  • 2