From ee47c21eedc69ee6d6f92484bd6373b16e2887a1 Mon Sep 17 00:00:00 2001 From: Alexandr Date: Fri, 19 Oct 2018 23:39:29 +0700 Subject: [PATCH 1/4] Add file size limit error --- pyrogram/client/client.py | 1 + 1 file changed, 1 insertion(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index b19bb486..d4afd9be 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1123,6 +1123,7 @@ class Client(Methods, BaseClient): progress_args: tuple = ()): part_size = 512 * 1024 file_size = os.path.getsize(path) + assert file_size < 1500 * 1024 * 1024, "Couldn't upload file bigger 1500MiB" file_total_parts = int(math.ceil(file_size / part_size)) is_big = True if file_size > 10 * 1024 * 1024 else False is_missing_part = True if file_id is not None else False From fa5759b07b0cb54fe912ff7d5195ef3efa675c56 Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Oct 2018 14:41:30 +0700 Subject: [PATCH 2/4] Thanks, that really looks better Co-Authored-By: TolichP --- pyrogram/client/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index d4afd9be..9deecd3d 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1123,7 +1123,8 @@ class Client(Methods, BaseClient): progress_args: tuple = ()): part_size = 512 * 1024 file_size = os.path.getsize(path) - assert file_size < 1500 * 1024 * 1024, "Couldn't upload file bigger 1500MiB" + if file_size > 1500 * 1024 * 1024: + raise ValueError("Telegram doesn't support uploading files bigger than 1500 MiB") file_total_parts = int(math.ceil(file_size / part_size)) is_big = True if file_size > 10 * 1024 * 1024 else False is_missing_part = True if file_id is not None else False From a0780d793da04ebbe51a6e426dc31fb9ed65d0ab Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sun, 21 Oct 2018 14:41:30 +0700 Subject: [PATCH 3/4] Apply code review suggestions --- pyrogram/client/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index d4afd9be..9deecd3d 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1123,7 +1123,8 @@ class Client(Methods, BaseClient): progress_args: tuple = ()): part_size = 512 * 1024 file_size = os.path.getsize(path) - assert file_size < 1500 * 1024 * 1024, "Couldn't upload file bigger 1500MiB" + if file_size > 1500 * 1024 * 1024: + raise ValueError("Telegram doesn't support uploading files bigger than 1500 MiB") file_total_parts = int(math.ceil(file_size / part_size)) is_big = True if file_size > 10 * 1024 * 1024 else False is_missing_part = True if file_id is not None else False From 09563067c77404326233ae5fbc49711c025b483d Mon Sep 17 00:00:00 2001 From: Dan <14043624+delivrance@users.noreply.github.com> Date: Sat, 3 Nov 2018 11:10:43 +0100 Subject: [PATCH 4/4] Add a check for 0 B file sizes --- pyrogram/client/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pyrogram/client/client.py b/pyrogram/client/client.py index 9deecd3d..33f11bad 100644 --- a/pyrogram/client/client.py +++ b/pyrogram/client/client.py @@ -1123,8 +1123,13 @@ class Client(Methods, BaseClient): progress_args: tuple = ()): part_size = 512 * 1024 file_size = os.path.getsize(path) + + if file_size == 0: + raise ValueError("File size equals to 0 B") + if file_size > 1500 * 1024 * 1024: raise ValueError("Telegram doesn't support uploading files bigger than 1500 MiB") + file_total_parts = int(math.ceil(file_size / part_size)) is_big = True if file_size > 10 * 1024 * 1024 else False is_missing_part = True if file_id is not None else False