Skip to content

Commit

Permalink
cleanup examples
Browse files Browse the repository at this point in the history
  • Loading branch information
siddhantgoel committed Sep 10, 2019
1 parent 86edd46 commit 698cd5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
9 changes: 5 additions & 4 deletions examples/bottle/stream_request_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,22 +19,23 @@ def root_page():
@bottle.post('/upload')
@bottle.view('upload.html')
def upload_page():
value = ValueTarget()
name = 'uploaded-file-tornado-{}.dat'.format(int(time()))
file = FileTarget(os.path.join(tempfile.gettempdir(), name))

value = ValueTarget()
file_ = FileTarget(os.path.join(tempfile.gettempdir(), name))

parser = StreamingFormDataParser(headers=bottle.request.headers)

parser.register('name', value)
parser.register('file', file)
parser.register('file', file_)

while True:
chunk = bottle.request.environ['wsgi.input'].read(8192)
if not chunk:
break
parser.data_received(chunk)

return {'name': value.value, 'filename': file.filename}
return {'name': value.value, 'filename': file_.filename}


if __name__ == '__main__':
Expand Down
10 changes: 7 additions & 3 deletions examples/tornado/stream_request_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,17 @@
from tornado.web import Application, RequestHandler, stream_request_body


one_gb = 100 * 1024 * 1024 * 1024


@stream_request_body
class UploadHandler(RequestHandler):
def prepare(self):
gigabyte = 1024 * 1024 * 1024
self.request.connection.set_max_body_size(100 * gigabyte)
self.value = ValueTarget()
self.request.connection.set_max_body_size(one_gb)

name = 'uploaded-file-tornado-{}.dat'.format(int(time()))

self.value = ValueTarget()
self.file_ = FileTarget(os.path.join(tempfile.gettempdir(), name))

self._parser = StreamingFormDataParser(headers=self.request.headers)
Expand Down

0 comments on commit 698cd5c

Please sign in to comment.