def optimally_image_download(self, key: str, /, *, chunk_size: int = 65536) -> NamedBytesIO:
        """
        Method downloads image by the following approach:
        Firstly we try to download the first N bytes of image which will be enough for determining image properties.
        If for some reason we cannot identify the required properties then we will download all file.

        Args:
            key (str): File on the bucket
            chunk_size (int, optional): The number of first bytes to download. Defaults to 65536 (64kB).

        Returns:
            BytesIO: Buffer with image
        """
        image_parser = ImageFile.Parser()

        chunk = self.download_range_of_bytes(key, stop_byte=chunk_size - 1)
        image_parser.feed(chunk)

        if image_parser.image:
            buff = NamedBytesIO(chunk)
            buff.filename = key
        else:
            buff = self.download_fileobj(key)
            image_size_in_bytes = len(buff.getvalue())
            slogger.glob.warning(
                f'The {chunk_size} bytes were not enough to parse "{key}" image. '
                f'Image size was {image_size_in_bytes} bytes. Image resolution was {Image.open(buff).size}. '
                f'Downloaded percent was {round(min(chunk_size, image_size_in_bytes) / image_size_in_bytes * 100)}')

        return buff

        Method downloads image by the following approach:
        Firstly we try to download the first N bytes of image which will be enough for determining image properties.
        If for some reason we cannot identify the required properties then we will download all file.

        Args:
            key (str): File on the bucket
            chunk_size (int, optional): The number of first bytes to download. Defaults to 65536 (64kB).

        Returns:
            BytesIO: Buffer with image
        
cvat/apps/engine/cloud_provider.py