Add a check for 0 B file sizes

This commit is contained in:
Dan 2018-11-03 11:10:43 +01:00 committed by GitHub
parent 361efb5889
commit 09563067c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1123,8 +1123,13 @@ class Client(Methods, BaseClient):
progress_args: tuple = ()): progress_args: tuple = ()):
part_size = 512 * 1024 part_size = 512 * 1024
file_size = os.path.getsize(path) file_size = os.path.getsize(path)
if file_size == 0:
raise ValueError("File size equals to 0 B")
if file_size > 1500 * 1024 * 1024: if file_size > 1500 * 1024 * 1024:
raise ValueError("Telegram doesn't support uploading files bigger than 1500 MiB") raise ValueError("Telegram doesn't support uploading files bigger than 1500 MiB")
file_total_parts = int(math.ceil(file_size / part_size)) file_total_parts = int(math.ceil(file_size / part_size))
is_big = True if file_size > 10 * 1024 * 1024 else False is_big = True if file_size > 10 * 1024 * 1024 else False
is_missing_part = True if file_id is not None else False is_missing_part = True if file_id is not None else False