igauravsehrawat
igauravsehrawat

Reputation: 3954

How to know file size after reading it as an object in python?

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

Upvotes: 0

Views: 120

Answers (1)

Billyoyo
Billyoyo

Reputation: 11

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)

Upvotes: 1

Related Questions