UploadMediaRequest

Both users and bots can use this method. See code examples.

---functions---
messages.uploadMedia#519bc2b1 peer:InputPeer media:InputMedia = MessageMedia

Returns

MessageMedia

This type can be an instance of either:

MessageMediaContactMessageMediaDice
MessageMediaDocumentMessageMediaEmpty
MessageMediaGameMessageMediaGeo
MessageMediaGeoLiveMessageMediaInvoice
MessageMediaPhotoMessageMediaPoll
MessageMediaUnsupportedMessageMediaVenue
MessageMediaWebPage

Parameters

peerInputPeerAnything entity-like will work if the library can find its Input version (e.g., usernames, Peer, User or Channel objects, etc.).
mediaInputMedia

Known RPC errors

This request can cause 3 known errors:

BotMissingErrorThis method can only be run by a bot.
MediaInvalidErrorMedia invalid.
PeerIdInvalidErrorAn invalid Peer was used. Make sure to pass the right peer type and that the value is valid (for instance, bots cannot start conversations).

You can import these from telethon.errors.

Example

Please refer to the documentation of client.send_file() to learn about the parameters and see several code examples on how to use it.

The method above is the recommended way to do it. If you need more control over the parameters or want to learn how it is implemented, open the details by clicking on the "Details" text.

from telethon.sync import TelegramClient
from telethon import functions, types

with TelegramClient(name, api_id, api_hash) as client:
    result = client(functions.messages.UploadMediaRequest(
        peer='username',
        media=types.InputMediaUploadedPhoto(
            file=client.upload_file('/path/to/file.jpg'),
            spoiler=True,
            stickers=[types.InputDocument(
                id=-12398745604826,
                access_hash=-12398745604826,
                file_reference=b'arbitrary\x7f data \xfa here'
            )],
            ttl_seconds=42
        )
    ))
    print(result.stringify())