diff options
Diffstat (limited to 'apitest.py')
-rw-r--r-- | apitest.py | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -19,7 +19,9 @@ import logging import os +import tempfile +import bottle import yaml import apifw @@ -34,7 +36,8 @@ class Api(apifw.Api): def __init__(self): super().__init__() - self._blob = None + fd, self._filename = tempfile.mkstemp() + os.close(fd) def find_missing_route(self, path): logging.info('find_missing_route called!\n') @@ -48,6 +51,7 @@ class Api(apifw.Api): 'method': 'PUT', 'path': '/upload', 'callback': self.upload, + 'big-blobs': True, }, { 'method': 'GET', @@ -66,23 +70,22 @@ class Api(apifw.Api): }) def upload(self, content_type, body, **kwargs): - self._blob = body + mega = 2 ** 20 + read = bottle.request.environ['wsgi.input'].read + with open(self._filename, 'wb') as f: + for part in body(mega): + f.write(part) + return apifw.Response({ 'status': apifw.HTTP_OK, - 'body': 'thank you for %s\n' % body.decode('ascii'), + 'body': 'thank you for your data\n', 'headers': { 'Content-Type': 'text/plain', }, }) def download(self, content_type, body, **kwargs): - return apifw.Response({ - 'status': apifw.HTTP_OK, - 'body': self._blob, - 'headers': { - 'Content-Type': 'text/plain', - }, - }) + raise apifw.StaticFile(self._filename) # We want logging. gunicorn provides logging, but only of its own |