Skip to content

Commit

Permalink
fix and pre-release
Browse files Browse the repository at this point in the history
  • Loading branch information
keryc committed Dec 28, 2020
1 parent c2bf9f6 commit e5e4859
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
11 changes: 7 additions & 4 deletions agave/blueprints/rest_api.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import mimetypes
from typing import Optional, Type
from urllib.parse import urlencode

Expand Down Expand Up @@ -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={
Expand Down
2 changes: 1 addition & 1 deletion agave/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.0.5'
__version__ = '0.0.7.dev0'
2 changes: 1 addition & 1 deletion examples/chalicelib/resources/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit e5e4859

Please sign in to comment.