I've looked through the Flask documentation, both the quickstart guide and the file upload guide, and can't find anything about getting the file size of a file. From what I understand, I'm only given the name of the file from on the users drive, and the name of input field that contained the uploaded file.
Apart from writing the file to the disk and then checking the size with os.path.getsize, is there a way to get the size of a file object?
I've been doing:
f.seek(0,SEEK_END)
f.tell()
There must be a better way right?
In case of an upload field like <input type="file" name="foo"/>
in the HTML page, request.files['foo']
gives you an object, which has an integer attribute called content_length
. This is the size of the uploaded file in bytes, see example usage here: https://github.com/dnet/photochecklist/blob/5072331/model.py#L78
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With