def download(self, to_path=None, name=None, chunk_size='<STR_LIT>',<EOL>convert_to_pdf=False):
<EOL>if to_path is None:<EOL><INDENT>to_path = Path()<EOL><DEDENT>else:<EOL><INDENT>if not isinstance(to_path, Path):<EOL><INDENT>to_path = Path(to_path)<EOL><DEDENT><DEDENT>if not to_path.exists():<EOL><INDENT>raise FileNotFoundError('<STR_LIT>'.format(to_path))<EOL><DEDENT>if name and not Path(name).suffix and self.name:<EOL><INDENT>name = name + Path(self.name).suffix<EOL><DEDENT>name = name or self.name<EOL>to_path = to_path / name<EOL>url = self.build_url(<EOL>self._endpoints.get('<STR_LIT>').format(id=self.object_id))<EOL>try:<EOL><INDENT>if chunk_size is None:<EOL><INDENT>stream = False<EOL><DEDENT>elif chunk_size == '<STR_LIT>':<EOL><INDENT>if self.size and self.size > SIZE_THERSHOLD:<EOL><INDENT>stream = True<EOL><DEDENT>else:<EOL><INDENT>stream = False<EOL><DEDENT><DEDENT>elif isinstance(chunk_size, int):<EOL><INDENT>stream = True<EOL><DEDENT>else:<EOL><INDENT>raise ValueError("<STR_LIT>"<EOL>"<STR_LIT>")<EOL><DEDENT>params = {}<EOL>if convert_to_pdf and Path(name).suffix in ALLOWED_PDF_EXTENSIONS:<EOL><INDENT>params['<STR_LIT>'] = '<STR_LIT>'<EOL><DEDENT>with self.con.get(url, stream=stream, params=params) as response:<EOL><INDENT>if not response:<EOL><INDENT>log.debug('<STR_LIT>'.format(<EOL>response.reason))<EOL>return False<EOL><DEDENT>with to_path.open(mode='<STR_LIT:wb>') as output:<EOL><INDENT>if stream:<EOL><INDENT>for chunk in response.iter_content(<EOL>chunk_size=chunk_size):<EOL><INDENT>if chunk:<EOL><INDENT>output.write(chunk)<EOL><DEDENT><DEDENT><DEDENT>else:<EOL><INDENT>output.write(response.content)<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except Exception as e:<EOL><INDENT>log.error(<EOL>'<STR_LIT>'.format(self.name,<EOL>str(e)))<EOL>return False<EOL><DEDENT>return True<EOL>
Downloads this file to the local drive. Can download the
        file in chunks with multiple requests to the server.

        :param to_path: a path to store the downloaded file
        :type to_path: str or Path
        :param str name: the name you want the stored file to have.
        :param int chunk_size: number of bytes to retrieve from
         each api call to the server. if auto, files bigger than
         SIZE_THERSHOLD will be chunked (into memory, will be
         however only 1 request)
        :param bool convert_to_pdf: will try to download the converted pdf
         if file extension in ALLOWED_PDF_EXTENSIONS
        :return: Success / Failure
        :rtype: bool