Skip to content

Commit daefba8

Browse files
fix: 上传大文件
1 parent b893f5a commit daefba8

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

byrdocs/__init__.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def request_token(data: dict[str, str]) -> str:
103103
@interrupt_handler
104104
def upload_progress(chunk, progress_bar: tqdm):
105105
progress_bar.update(chunk)
106-
106+
107107
@interrupt_handler
108108
def _ask_for_init(file_name: str=None) -> str:
109109
ask_for_init(file_name)
@@ -112,31 +112,30 @@ def _ask_for_init(file_name: str=None) -> str:
112112
def main():
113113
argcomplete.autocomplete(command_parser)
114114
args = command_parser.parse_args()
115-
115+
116116
if not args.command and not args.file:
117117
menu_command = main_menu()
118118
if menu_command.command == 'upload_2':
119119
args.command = 'upload'
120120
args.file = menu_command.file
121121
else:
122122
args.command = menu_command.command
123-
123+
124124
if args.command not in ['login', 'logout', 'upload', 'init', 'validate']:
125125
args.file = args.command
126126
args.command = 'upload'
127127

128128
if args.file and not args.command:
129129
args.command = 'upload'
130-
130+
131131
if args.command == 'init':
132132
_ask_for_init()
133133
exit(0)
134-
134+
135135
if args.command == 'validate':
136136
print(warn("该功能尚未实现"))
137137
exit(0)
138138

139-
140139
config_dir = pathlib.Path.home() / ".config" / "byrdocs"
141140
if not config_dir.exists():
142141
config_dir.mkdir(parents=True)
@@ -160,7 +159,7 @@ def login(token=None):
160159
print(info("请在浏览器中访问以下链接进行登录:"))
161160
print("\t" + login_data["loginURL"])
162161
token = request_token(login_data)
163-
162+
164163
with token_path.open("w") as f:
165164
f.write(token)
166165
print(info(f"登录成功,凭证已保存到 {token_path.absolute()}"))
@@ -255,8 +254,9 @@ def login(token=None):
255254
progress_bar = tqdm(total=file_size, unit='B', unit_scale=True, desc="Uploading")
256255

257256
# https://blog.csdn.net/weixin_44123540/article/details/118492260
258-
GB = 1024**3
259-
upload_config = boto3.s3.transfer.TransferConfig(multipart_threshold=2*GB)
257+
# 对于上传 100MB 的文件会有限制,需要分块上传
258+
MB = 1024**2
259+
upload_config = boto3.s3.transfer.TransferConfig(multipart_threshold=100*MB, multipart_chunksize=50*MB)
260260

261261
try:
262262
s3_client.upload_file(
@@ -275,7 +275,7 @@ def login(token=None):
275275
UploadHistory().add(pathlib.Path(file).name, md5, time())
276276
print(info("文件上传成功!"))
277277
print(f"\t文件地址: {baseURL}/files/{new_filename}")
278-
278+
279279
try:
280280
if ask_for_confirmation("是否立即为该文件录入元信息?"):
281281
_ask_for_init(new_filename)

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ requires = ["setuptools>=61.0"]
33
build-backend = "setuptools.build_meta"
44
[project]
55
name = "byrdocs_cli"
6-
version = "0.5.0"
6+
version = "0.5.1"
77
authors = [
88
{ name="Rikka", email="[email protected]" },
99
]

0 commit comments

Comments
 (0)