diff --git a/maxapi/connection/base.py b/maxapi/connection/base.py index c604c68..0e25d30 100644 --- a/maxapi/connection/base.py +++ b/maxapi/connection/base.py @@ -4,7 +4,6 @@ import os import mimetypes from typing import TYPE_CHECKING, Any, Optional -from uuid import uuid4 import aiofiles import puremagic @@ -156,6 +155,7 @@ class BaseConnection: async def upload_file_buffer( self, + filename: str, url: str, buffer: bytes, type: UploadType @@ -182,7 +182,7 @@ class BaseConnection: mime_type = f"{type.value}/*" ext = '' - basename = f'{uuid4()}{ext}' + basename = f'{filename}{ext}' form = FormData() form.add_field( diff --git a/maxapi/types/input_media.py b/maxapi/types/input_media.py index 5ec9b26..df01e94 100644 --- a/maxapi/types/input_media.py +++ b/maxapi/types/input_media.py @@ -68,13 +68,15 @@ class InputMediaBuffer: type (UploadType): Тип файла, определенный по содержимому. """ - def __init__(self, buffer: bytes): + def __init__(self, buffer: bytes, filename: str | None = None): """ Инициализирует объект медиафайла из буфера. Args: buffer (IO): Буфер с содержимым файла. + filename (str): Название файла (по умолчанию присваивается uuid4). """ + self.filename = filename self.buffer = buffer self.type = self.__detect_file_type(buffer) diff --git a/maxapi/utils/message.py b/maxapi/utils/message.py index aa0de48..0fbe13f 100644 --- a/maxapi/utils/message.py +++ b/maxapi/utils/message.py @@ -2,6 +2,7 @@ from __future__ import annotations from typing import TYPE_CHECKING from json import loads +from uuid import uuid4 from ..types.input_media import InputMedia, InputMediaBuffer from ..enums.upload_type import UploadType @@ -46,6 +47,7 @@ async def process_input_media( ) elif isinstance(att, InputMediaBuffer): upload_file_response = await base_connection.upload_file_buffer( + filename=att.filename or str(uuid4()), url=upload.url, buffer=att.buffer, type=att.type,