Downloading large file from S3 is failed with django

I uploaded a large zip file (6.7GB) to S3 via Django code:

@retry(stop=stop_after_attempt(3), wait=wait_exponential(multiplier=3), reraise=True)
@aws_exception_handler
def upload_file(self, file_path, key, tags=None, extra_args={}):
    absolute_key = generate_key(key)
    transfer_config = TransferConfig(
        multipart_threshold=1024 * 1024 * 4,
        multipart_chunksize=1024 * 1024 * 16,
        max_io_queue=1000,
        max_concurrency=max_workers,
        use_threads=True
    )
    with open(file_path, 'rb') as data:
        self.s3_client.upload_fileobj(data, self.bucket_name, absolute_key, Config=transfer_config,
                                                 ExtraArgs=extra_args)

    if tags:
        try:
            put_object_tagging_kwargs = {
                'Key': self._get_absolute_key(key),
                'Bucket': self.bucket_name,
                'Tagging': {
                    'TagSet': [
                        {'Key': tag_key, 'Value': tag_value} for tag_key, tag_value in tags.items()
                    ]
                }
            }
            self.s3_client.put_object_tagging(**put_object_tagging_kwargs)
        except Exception as ex:
            raise ex

Then I tried to download it through the UI with this code in the server (I tried each of those methods, and the result is the same as I describe below):

def check_file_exists_retry_predicate(exception):
return False if isinstance(exception, CloudStorageObjectDoesNotExists) else True

@retry(
    retry=retry_if_exception(check_file_exists_retry_predicate),
    stop=stop_after_attempt(3),
    wait=wait_exponential(multiplier=3),
    reraise=True
)
@aws_exception_handler
def download(self, key, stream=False):
    obj = self.s3_client.get_object(Bucket=self.bucket_name, Key=self.generate_key(key))
    if stream:
        return obj['Body']
    return obj['Body'].read().decode(self._decode_format)

@retry(
    retry=retry_if_exception(check_file_exists_retry_predicate),
    stop=stop_after_attempt(3),
    wait=wait_exponential(multiplier=3),
    reraise=True
)
@aws_exception_handler
def download_file(self, file_path, key):
    file_folder_path = os.path.dirname(file_path)
    if file_folder_path:
        mkdir_by_path(file_folder_path)

    with open(file_path, 'wb') as fh:
        transfer_config = TransferConfig(
        multipart_threshold=1024 * 1024 * 4,
        multipart_chunksize=1024 * 1024 * 16,
        max_io_queue=1000,
        max_concurrency=max_workers,
        use_threads=True
    )
        absolute_key = self.generate_key(key)
        self.s3_client.download_fileobj(self.bucket_name, absolute_key, fh, Config=transfer_config)

The download starts but stops suddenly after a few seconds and Chrome shows "check internet connection". The connection is good (I can download a large file from Azure) and it happens in Safari too. When I download this file from S3 UI - it works.

Do you have any ideas what to check or how to solve it?

Back to Top