mirror of
https://github.com/LonamiWebs/Telethon.git
synced 2024-11-22 09:26:37 +03:00
Fix uploading big files (closes #2)
This commit is contained in:
parent
3f24cb17c3
commit
af4514b15e
|
@ -30,7 +30,7 @@ from telethon.tl.functions.upload import (
|
|||
# All the types we need to work with
|
||||
from telethon.tl.types import (
|
||||
ChatPhotoEmpty, DocumentAttributeAudio, DocumentAttributeFilename,
|
||||
InputDocumentFileLocation, InputFile, InputFileLocation,
|
||||
InputDocumentFileLocation, InputFile, InputFileBig, InputFileLocation,
|
||||
InputMediaUploadedDocument, InputMediaUploadedPhoto, InputPeerEmpty,
|
||||
MessageMediaContact, MessageMediaDocument, MessageMediaPhoto,
|
||||
UserProfilePhotoEmpty)
|
||||
|
@ -422,7 +422,7 @@ class TelegramClient:
|
|||
|
||||
# Multiply the datetime timestamp by 10^6 to get the ticks
|
||||
# This is high likely going to be unique
|
||||
file_id = int(datetime.now().timestamp() * (10**6))
|
||||
file_id = utils.generate_random_long()
|
||||
hash_md5 = md5()
|
||||
|
||||
with open(file_path, 'rb') as file:
|
||||
|
@ -441,7 +441,10 @@ class TelegramClient:
|
|||
# Invoke the file upload and increment both the part index and MD5 checksum
|
||||
result = self.invoke(request)
|
||||
if result:
|
||||
if not is_large:
|
||||
# No need to update the hash if it's a large file
|
||||
hash_md5.update(part)
|
||||
|
||||
if progress_callback:
|
||||
progress_callback(file.tell(), file_size)
|
||||
else:
|
||||
|
@ -453,6 +456,12 @@ class TelegramClient:
|
|||
file_name = path.basename(file_path)
|
||||
|
||||
# After the file has been uploaded, we can return a handle pointing to it
|
||||
if is_large:
|
||||
return InputFileBig(
|
||||
id=file_id,
|
||||
parts=part_count,
|
||||
name=file_name)
|
||||
else:
|
||||
return InputFile(
|
||||
id=file_id,
|
||||
parts=part_count,
|
||||
|
|
Loading…
Reference in New Issue
Block a user