From e5e4859dc02654ef726ab479e983cfc887127cef Mon Sep 17 00:00:00 2001 From: keryc Diaz Date: Mon, 28 Dec 2020 15:25:37 -0600 Subject: [PATCH] fix and pre-release --- agave/blueprints/rest_api.py | 11 +++++++---- agave/version.py | 2 +- examples/chalicelib/resources/files.py | 2 +- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/agave/blueprints/rest_api.py b/agave/blueprints/rest_api.py index c5aadb87..04331b57 100644 --- a/agave/blueprints/rest_api.py +++ b/agave/blueprints/rest_api.py @@ -1,3 +1,4 @@ +import mimetypes from typing import Optional, Type from urllib.parse import urlencode @@ -148,10 +149,12 @@ def retrieve(id: str): except DoesNotExist: raise NotFoundError('Not valid id') - if hasattr(cls, 'get_file'): - file, mimetype = cls.get_file(data) - extention = mimetype.split('/')[1] - filename = f'{cls.model._class_name}.{extention}' + # This is the case in which the return is not an application/$ + # but can be some type of file such as image, xml, zip or pdf + if hasattr(cls, 'download'): + file, mimetype = cls.download(data) + extension = mimetypes.guess_extension(mimetype) + filename = f'{cls.model._class_name}.{extension}' return Response( body=file.read(), headers={ diff --git a/agave/version.py b/agave/version.py index eead3198..f6dadc5d 100644 --- a/agave/version.py +++ b/agave/version.py @@ -1 +1 @@ -__version__ = '0.0.5' +__version__ = '0.0.7.dev0' diff --git a/examples/chalicelib/resources/files.py b/examples/chalicelib/resources/files.py index b33ba3b1..cce145b6 100644 --- a/examples/chalicelib/resources/files.py +++ b/examples/chalicelib/resources/files.py @@ -19,6 +19,6 @@ class File: get_query_filter = generic_query @classmethod - def get_file(cls, data: FileModel) -> Tuple[BytesIO, str]: + def download(cls, data: FileModel) -> Tuple[BytesIO, str]: mimetype = app.current_request.headers.get('accept') return BytesIO(bytes('Hello', 'utf-8')), mimetype