def upload_file(self, files, name=""): if not (files and os.path.isfile(files)): return files if not name: name = os.path.basename(files) LOGGER.info(f"Try to upload file {name}") _url = f"{self.kbserver}/file/upload" with open(files, "rb") as fin: files = {"file": fin} outurl = http_request(url=_url, method="POST", files=files) if FileOps.is_remote(outurl): return outurl outurl = outurl.lstrip("/") FileOps.delete(files) return f"{self.kbserver}/{outurl}"
def update_db(self, task_info_file): _url = f"{self.kbserver}/update" try: with open(task_info_file, "rb") as fin: files = {"task": fin} outurl = http_request(url=_url, method="POST", files=files) except Exception as err: LOGGER.error(f"Update kb error: {err}") outurl = None else: if not FileOps.is_remote(outurl): outurl = outurl.lstrip("/") outurl = f"{self.kbserver}/{outurl}" FileOps.delete(task_info_file) return outurl