Description
Hi!
We have a good feature for streaming HTTP body (decorator stream_request_body).
Using stream_request_body we get chunks of HTTP body in data_received method. But this data is raw. And It will be cool to have a support for higher level tool to work with streaming body (in case of multipart_form_data).
If it is not solved yet I can do this, but I'm not sure about architecture for solution.
I want to implement smth like StreamParser, which will get boundary and infinite generator which will return file-like objects. This parser we can instantiate in prepare
method and then simply pass chunks in data_received
method to it. Parser will write to these file-like objects and efficiently use RAM. But this solution has drawbacks. At least, we don't have universal solution in case if we want to handle data with some logic. Also we can't return any meta info from these file-like objects. But there can be important information such as ObjectId in case of using for example mongodb gridfs.
Another solution is to implement a subclass of RequestHandler with stream_request_body decorator and overridden prepare
and data_received
methods. We can add some extra abstract methods such as open_file
, close_file
, new_data
and pass to them info about current state and chunks which we can write to file and do whatever we want without thinking about boundaries, headers.
What do you think about it?