Skip to content

Commit 712b390

Browse files
committed
Add a retry mechanism when uploading chunks
1 parent a2263ad commit 712b390

File tree

1 file changed

+18
-14
lines changed

1 file changed

+18
-14
lines changed

pyrogram/client/client.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1439,21 +1439,25 @@ def save_file(self,
14391439
md5_sum = "".join([hex(i)[2:].zfill(2) for i in md5_sum.digest()])
14401440
break
14411441

1442-
if is_big:
1443-
rpc = functions.upload.SaveBigFilePart(
1444-
file_id=file_id,
1445-
file_part=file_part,
1446-
file_total_parts=file_total_parts,
1447-
bytes=chunk
1448-
)
1449-
else:
1450-
rpc = functions.upload.SaveFilePart(
1451-
file_id=file_id,
1452-
file_part=file_part,
1453-
bytes=chunk
1454-
)
1442+
for _ in range(3):
1443+
if is_big:
1444+
rpc = functions.upload.SaveBigFilePart(
1445+
file_id=file_id,
1446+
file_part=file_part,
1447+
file_total_parts=file_total_parts,
1448+
bytes=chunk
1449+
)
1450+
else:
1451+
rpc = functions.upload.SaveFilePart(
1452+
file_id=file_id,
1453+
file_part=file_part,
1454+
bytes=chunk
1455+
)
14551456

1456-
assert session.send(rpc), "Couldn't upload file"
1457+
if session.send(rpc):
1458+
break
1459+
else:
1460+
raise AssertionError("Telegram didn't accept chunk #{} of {}".format(file_part, path))
14571461

14581462
if is_missing_part:
14591463
return

0 commit comments

Comments
 (0)