Commit 007cb0a1 authored by D1plo1d's avatar D1plo1d

Patching file upload to use less memory.

parent 00156cc3
...@@ -94,13 +94,16 @@ class StopHandler(tornado.web.RequestHandler): ...@@ -94,13 +94,16 @@ class StopHandler(tornado.web.RequestHandler):
prontserve.do_stop() prontserve.do_stop()
self.finish("ACK") self.finish("ACK")
from cStringIO import StringIO
@tornado.web.stream_body @tornado.web.stream_body
class JobsHandler(tornado.web.RequestHandler): class JobsHandler(tornado.web.RequestHandler):
def post(self): def post(self):
self.read_bytes = 0 self.read_bytes = 0
self.total_bytes = self.request.content_length self.total_bytes = self.request.content_length
self.chunks = [] self.file_str = StringIO()
print self.request print self.request
session_uuid = self.get_argument("session_uuid", None) session_uuid = self.get_argument("session_uuid", None)
print "me" print "me"
...@@ -115,7 +118,7 @@ class JobsHandler(tornado.web.RequestHandler): ...@@ -115,7 +118,7 @@ class JobsHandler(tornado.web.RequestHandler):
def read_chunks(self, chunk=''): def read_chunks(self, chunk=''):
self.read_bytes += len(chunk) self.read_bytes += len(chunk)
self.chunks.append(chunk) self.file_str.write(chunk)
if chunk: self.process_chunk() if chunk: self.process_chunk()
chunk_length = min(100000, self.request.content_length - self.read_bytes) chunk_length = min(100000, self.request.content_length - self.read_bytes)
...@@ -123,7 +126,7 @@ class JobsHandler(tornado.web.RequestHandler): ...@@ -123,7 +126,7 @@ class JobsHandler(tornado.web.RequestHandler):
self.request.connection.stream.read_bytes( self.request.connection.stream.read_bytes(
chunk_length, self.read_chunks) chunk_length, self.read_chunks)
else: else:
self.request._on_request_body(''.join(self.chunks), self.uploaded) self.request._on_request_body(self.file_str.getvalue(), self.uploaded)
def process_chunk(self): def process_chunk(self):
print self.get_argument("session_uuid", None) print self.get_argument("session_uuid", None)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment