diff --git a/backend/api/views/function.py b/backend/api/views/function.py index cc692749b..e906c450d 100644 --- a/backend/api/views/function.py +++ b/backend/api/views/function.py @@ -230,6 +230,7 @@ def image(self, request, *args, **kwargs): status=status.HTTP_404_NOT_FOUND, ) - # TODO we love hard-coded size, see also api.views.utils.PermissionMixin._download_remote_file - response = CustomFileResponse(streaming_content=(chunk for chunk in function_image.file.chunks(512 * 1024))) + response = CustomFileResponse( + streaming_content=(chunk for chunk in function_image.file.chunks(self.chunk_size)) + ) return response diff --git a/backend/api/views/utils.py b/backend/api/views/utils.py index baea84e41..48605757a 100644 --- a/backend/api/views/utils.py +++ b/backend/api/views/utils.py @@ -66,6 +66,7 @@ def set_headers(self, filelike): class PermissionMixin(object): authentication_classes = api_settings.DEFAULT_AUTHENTICATION_CLASSES + [BasicAuthentication] permission_classes = [IsAuthorized] + chunk_size = 512 * 1024 def check_access(self, channel_name: str, user, asset, is_proxied_request: bool) -> None: """Returns true if API consumer is allowed to access data. @@ -142,7 +143,7 @@ def _download_remote_file(self, channel_name: str, owner: str, url: str) -> djan headers={HTTP_HEADER_PROXY_ASSET: "True"}, ) response = CustomFileResponse( - streaming_content=(chunk for chunk in proxy_response.iter_content(512 * 1024)), + streaming_content=(chunk for chunk in proxy_response.iter_content(self.chunk_size)), status=proxy_response.status_code, )