(self, filename: str, target_path: str, mode: str = "cover",
call_log: Callable[[int, str], None] = None)
| 432 | |
| 433 | # mode -> cover: 覆盖,ignore: 跳过,rename:重命名 |
| 434 | def upload_file(self, filename: str, target_path: str, mode: str = "cover", |
| 435 | call_log: Callable[[int, str], None] = None) -> str: |
| 436 | if not os.path.isfile(filename): |
| 437 | return "文件:{}不存在".format(filename) |
| 438 | |
| 439 | target_file = os.path.join(target_path, os.path.basename(filename)) |
| 440 | exits, err = self.target_file_exits(target_file) |
| 441 | if err: |
| 442 | return err |
| 443 | if exits and mode == "ignore": |
| 444 | call_log(0, "文件上传:{} -> {},目标文件已存在,跳过上传".format(filename, target_file)) |
| 445 | return "" |
| 446 | if exits and mode == "rename": |
| 447 | upload_name = "{}_{}".format(os.path.basename(filename), public.md5(filename)) |
| 448 | call_log(0, "文件上传:{} -> {},目标文件已存在,将重命名为{}".format(filename, target_file, upload_name)) |
| 449 | else: |
| 450 | upload_name = os.path.basename(filename) |
| 451 | |
| 452 | if os.path.getsize(filename) > 1024 * 1024 * 5: |
| 453 | return self._upload_big_file(filename, target_path, upload_name, call_log) |
| 454 | else: |
| 455 | return self._upload_little_file(filename, target_path, upload_name, call_log) |
| 456 | |
| 457 | def target_file_exits(self, target_file: str) -> Tuple[bool, str]: |
| 458 | data, err = self._request("/files", "upload_files_exists", pdata={ |
nothing calls this directly
no test coverage detected