1

With Python Flask, it's not so difficult to handle put request and get the content in request.data. However, it is triggered when the whole data transmission completes and they're all in the buffer. What if I want the web server to be just a pipe and handle the incoming stream chunk by chunk, not assembling them all?

Something like how Nodejs does:

.on('data', function (chunk)
{
    //Process the chunk
});
Levy
  • 11
  • 3
  • possible duplicate of [Flask and Transfer-Encoding: chunked](http://stackoverflow.com/questions/14146824/flask-and-transfer-encoding-chunked) – metatoaster Jul 28 '15 at 02:36

1 Answers1

0

You are looking for request.stream which gives you access to the underlying wsgi.input stream to read from:

CHUNK_SIZE = calculate_chunk_size(request)  # Your magic here
while check_some_condition(request):
    chunk = request.stream.read(CHUNK_SIZE)
    # Process chunk
Sean Vieira
  • 155,703
  • 32
  • 311
  • 293