Python - Getting file object file size from file upload in Flask

I looked at the Flask documentation, both the quick start guide and the file upload guide, and can't find anything about getting the file size. As I understand it, I am assigned the name of the file on the user's disk and the name of the input field containing the downloaded file.

Besides burning the file to disk and then checking the size with os.path.getsize, is there any way to get the size of the object file?

I do:

f.seek(0,SEEK_END) f.tell() 

Should the right path be right?

+7
source share
1 answer

In the case of a download field, such as <input type="file" name="foo"/> on the HTML page, request.files['foo'] provides you with an object that has an integer attribute content_length . This is the size of the downloaded file in bytes, see an example usage here: https://github.com/dnet/photochecklist/blob/5072331/model.py#L78

+2
source

All Articles