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