diff --git a/README.md b/README.md index b4120fe..e42d28d 100644 --- a/README.md +++ b/README.md @@ -742,6 +742,7 @@ BaiduPCS-Py upload --max-workers 4 [OPTIONS] [LOCALPATHS]... REMOTEDIR | --no-ignore-existing, --NI | 上传已经存在的文件 | | --no-show-progress, --NP | 不显示上传进度 | | --check-md5, --CM | 分段上传后检查 md5。注意检查上传后大文件的 md5,可能会花数分中(2G 的文件需要大约 5 分钟) | +| --enable-rapid-upload, --R | 启用秒传,默认启用(秒传API有变动,如果上传失败,请关闭秒传后在试) | ## 同步本地目录到远端 diff --git a/baidupcs_py/app/app.py b/baidupcs_py/app/app.py index d3260ff..6ab0c9d 100644 --- a/baidupcs_py/app/app.py +++ b/baidupcs_py/app/app.py @@ -1183,6 +1183,7 @@ def play( is_flag=True, help="分段上传后检查md5。注意检查上传后大文件的md5,可能会花数分中(2G 的文件需要大约5分钟)", ) +@click.option("--enable-rapid-upload", "--R", is_flag=True, help="启用秒传") @click.pass_context @handle_error @multi_user_do @@ -1197,6 +1198,7 @@ def upload( no_ignore_existing, no_show_progress, check_md5, + enable_rapid_upload, ): """上传文件""" @@ -1236,6 +1238,7 @@ def upload( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) @@ -1258,6 +1261,7 @@ def upload( is_flag=True, help="分段上传后检查md5。注意检查上传后大文件的md5,可能会花数分中(2G 的文件需要大约5分钟)", ) +@click.option("--enable-rapid-upload", "--R", is_flag=True, help="启用秒传") @click.pass_context @handle_error @multi_user_do @@ -1270,6 +1274,7 @@ def sync( max_workers, no_show_progress, check_md5, + enable_rapid_upload, ): """同步本地目录到远端""" @@ -1303,6 +1308,7 @@ def sync( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) diff --git a/baidupcs_py/commands/sync.py b/baidupcs_py/commands/sync.py index 25b5b06..9acb067 100644 --- a/baidupcs_py/commands/sync.py +++ b/baidupcs_py/commands/sync.py @@ -48,6 +48,7 @@ def sync( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): localdir = Path(localdir).as_posix() remotedir = Path(remotedir).as_posix() @@ -119,6 +120,7 @@ def sync( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) if to_deletes: diff --git a/baidupcs_py/commands/upload.py b/baidupcs_py/commands/upload.py index 23e6188..4305f78 100644 --- a/baidupcs_py/commands/upload.py +++ b/baidupcs_py/commands/upload.py @@ -134,6 +134,7 @@ def upload( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): """Upload from_tos @@ -175,6 +176,7 @@ def upload( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) elif upload_type == UploadType.Many: upload_many( @@ -190,6 +192,7 @@ def upload( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) @@ -335,6 +338,7 @@ def upload_one_by_one( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): """Upload files one by one with uploading the slices concurrently""" @@ -355,6 +359,7 @@ def upload_one_by_one( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) logger.debug("======== Uploading end ========") @@ -385,6 +390,7 @@ def upload_file_concurrently( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): """Uploading one file by uploading it's slices concurrently""" @@ -421,7 +427,7 @@ def callback_for_slice(idx: int, monitor: MultipartEncoderMonitor): content_md5 = "" content_crc32 = 0 - if encrypt_type == EncryptType.No and encrypt_io_len > 256 * constant.OneK: + if encrypt_type == EncryptType.No and encrypt_io_len > 256 * constant.OneK and enable_rapid_upload: # Rapid Upload slice256k_md5, content_md5, content_crc32, _ = rapid_upload_params(encrypt_io) ok = _rapid_upload( @@ -560,6 +566,7 @@ def upload_many( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): """Upload files concurrently that one file is with one connection""" @@ -590,6 +597,7 @@ def upload_many( user_id=user_id, user_name=user_name, check_md5=check_md5, + enable_rapid_upload=enable_rapid_upload, ) futs[fut] = from_to @@ -638,6 +646,7 @@ def upload_file( user_id: Optional[int] = None, user_name: Optional[str] = None, check_md5: bool = False, + enable_rapid_upload: bool = True, ): """Upload one file with one connection""" @@ -673,7 +682,7 @@ def callback_for_slice(monitor: MultipartEncoderMonitor): content_md5 = "" content_crc32 = 0 - if encrypt_type == EncryptType.No and encrypt_io_len > 256 * constant.OneK: + if encrypt_type == EncryptType.No and encrypt_io_len > 256 * constant.OneK and enable_rapid_upload: # Rapid Upload slice256k_md5, content_md5, content_crc32, _ = rapid_upload_params(encrypt_io) ok = _rapid_upload(