summaryrefslogtreecommitdiff
path: root/apitest.py
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2018-03-24 15:48:12 +0200
committerLars Wirzenius <liw@liw.fi>2018-03-24 18:14:47 +0200
commitf299215889b6acf8aff86243d50d4a54bb528021 (patch)
tree138c1c06d5645238f4244e1e26f380091143f370 /apitest.py
parentcdcf71634ffc16a3cd09a2ee2641ddbaaba165ec (diff)
downloadapifw-f299215889b6acf8aff86243d50d4a54bb528021.tar.gz
Change: support up/download of large blobs
This is very ugly. But it solves the problem, and apifw will need to be re-designed to support this properly.
Diffstat (limited to 'apitest.py')
-rw-r--r--apitest.py23
1 files changed, 13 insertions, 10 deletions
diff --git a/apitest.py b/apitest.py
index d28a61b..0a55756 100644
--- a/apitest.py
+++ b/apitest.py
@@ -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