Can I have sinatra not read the entire request body into memory?
        Posted  
        
            by Chris Markle
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by Chris Markle
        
        
        
        Published on 2010-06-12T05:08:20Z
        Indexed on 
            2010/06/12
            5:12 UTC
        
        
        Read the original article
        Hit count: 231
        
sinatra
|httprequest
Say I have a sinatra route ala:
put '/data' do
  request.body.read
  [...]
end
It appears that the entire request.body is read into memory. Is there a way to consume the body as it comes into the system, rather than having it all buffered in Rack/sinatra beforehand?
I see I can do this to read the body in parts, but the entire body still seems to be read into memory beforehand.
put '/data' do
  while request.body.read(1024) != nil 
    [...]
  end
  [...]
end
        © Stack Overflow or respective owner