Skip to content
This repository

send_file uses 2x file's size in memory with conditional = True #361

Open
qxcv opened this Issue December 12, 2011 · 1 comment

2 participants

qxcv ThomasWaldmann
qxcv

https://github.com/mitsuhiko/flask/blob/master/flask/helpers.py#L423

Conditional responses (Response.make_conditional()) cause the iterator to be converted to a list (which stores the contents of the file in memory) and then ''.join() is used on the list (!!) which stores the contents of the file in memory AGAIN so Flask can use len() to determine content length. So for a short time it uses twice the item size in memory until the list conversion function returns the string from ''.join() and the original list is destroyed.

This isn't mentioned anywhere in the Flask docs, and can be avoided by calculating the file size and setting the Content-Length header using os.path.getsize() or fp.seek() and fp.tell() before rv.make_conditional is called.

ThomasWaldmann

is this still true?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.