From 2ca198fc35d2d62215009f581e09afa6f9ac3eb0 Mon Sep 17 00:00:00 2001 From: Ray Liu Date: Thu, 11 Jul 2024 08:35:38 +1000 Subject: [PATCH 1/2] add content disposition header for s3 presign api --- data_portal/viewsets/s3object.py | 3 ++- data_portal/viewsets/utils.py | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/data_portal/viewsets/s3object.py b/data_portal/viewsets/s3object.py index 6d767c38..fb25a184 100644 --- a/data_portal/viewsets/s3object.py +++ b/data_portal/viewsets/s3object.py @@ -42,7 +42,8 @@ def get_queryset(self): @action(detail=True) def presign(self, request, pk=None): obj: S3Object = self.get_object() - return _presign_response(obj.bucket, obj.key) + content_disposition = request.headers.get('Content-Disposition', 'attachment') + return _presign_response(obj.bucket, obj.key, content_disposition) @action(detail=True) def status(self, request, pk=None): diff --git a/data_portal/viewsets/utils.py b/data_portal/viewsets/utils.py index 566c396b..3d17862e 100644 --- a/data_portal/viewsets/utils.py +++ b/data_portal/viewsets/utils.py @@ -12,8 +12,11 @@ def _error_response(message, status_code=400, err=None) -> Response: ) -def _presign_response(bucket, key) -> Response: - response = libs3.presign_s3_file(bucket, key) +def _presign_response(bucket, key, content_disposition) -> Response: + + # need modify libumccr to pass content_disposition to libs3.presign_s3_file + response = libs3.presign_s3_file(bucket, key, content_disposition) + if response[0]: return Response({'signed_url': response[1]}) else: From 00d0ab09f2679a40c69e068653b9ebc0ee4b1ef2 Mon Sep 17 00:00:00 2001 From: Ray Liu Date: Thu, 11 Jul 2024 12:07:32 +1000 Subject: [PATCH 2/2] update the libumccr version --- data_portal/viewsets/utils.py | 3 --- requirements.txt | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/data_portal/viewsets/utils.py b/data_portal/viewsets/utils.py index 3d17862e..dc355559 100644 --- a/data_portal/viewsets/utils.py +++ b/data_portal/viewsets/utils.py @@ -13,10 +13,7 @@ def _error_response(message, status_code=400, err=None) -> Response: def _presign_response(bucket, key, content_disposition) -> Response: - - # need modify libumccr to pass content_disposition to libs3.presign_s3_file response = libs3.presign_s3_file(bucket, key, content_disposition) - if response[0]: return Response({'signed_url': response[1]}) else: diff --git a/requirements.txt b/requirements.txt index be9b5aff..12092e4b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -10,7 +10,7 @@ python-dateutil==2.9.0.post0 google-auth==2.30.0 Werkzeug==3.0.3 libica==2.4.0 -libumccr==0.3.0 +libumccr==0.4.0rc4 gspread==5.12.4 gspread-pandas==3.3.0 sample-sheet==0.13.0