werkzeug icon indicating copy to clipboard operation
werkzeug copied to clipboard

Keeping file uploads in memory

Open soonahn opened this issue 12 years ago • 1 comments

Inside of default_stream_factory, is a way I can add a setting such that I can set the threshold of how large total_content_length can be before it writes to a temporary file?

Are there settings (and examples of such) that I can see and hence patch this myself?

Or am I forced to fork werkzeug to implement my own method?

soonahn avatar Jun 12 '14 01:06 soonahn

def my_stream_factory(total_content_length, filename, content_type, content_length=None):
    ...  # do something special

class MyFormDataParser(FormDataParser):
    def __init__(self, *args, **kwargs):
        kwargs.setdefault("stream_factory", my_stream_factory)
        super().__init__(*args, **kwargs)

class MyRequest(Request):
    form_data_parser_class = MyFormDataParser

class MyFlask(Flask):
    request_class = MyRequest

davidism avatar Nov 12 '18 20:11 davidism