Hide navigation sidebar
Hide table of contents sidebar
PTB has undergone significant changes in v20. Please read the documentation carefully and also check out the transition guide in the wiki.
Back to top
Toggle table of contents sidebar

# InputFile

class telegram.InputFile(obj, filename=None, attach=False)

  Bases: `object`

  This object represents a Telegram InputFile.

  Use In

  - `telegram.Bot.send_animation()`

  - `telegram.Bot.send_audio()`

  - `telegram.Bot.send_document()`

  - `telegram.Bot.send_photo()`

  - `telegram.Bot.send_sticker()`

  - `telegram.Bot.send_video_note()`

  - `telegram.Bot.send_video()`

  - `telegram.Bot.send_voice()`

  - `telegram.Bot.set_chat_photo()`

  - `telegram.Bot.set_sticker_set_thumbnail()`

  - `telegram.Bot.set_webhook()`

  - `telegram.Bot.upload_sticker_file()`

  Available In

  - `telegram.InputMedia.media`

  - `telegram.InputMediaAnimation.media`

  - `telegram.InputMediaAnimation.thumbnail`

  - `telegram.InputMediaAudio.media`

  - `telegram.InputMediaAudio.thumbnail`

  - `telegram.InputMediaDocument.media`

  - `telegram.InputMediaDocument.thumbnail`

  - `telegram.InputMediaPhoto.media`

  - `telegram.InputMediaVideo.media`

  - `telegram.InputMediaVideo.thumbnail`

  - `telegram.InputSticker.sticker`

  Changed in version 20.0:

  - The former attribute `attach` was renamed to `attach_name`.

  - Method `is_image` was removed. If you pass `bytes` to `obj` and would like to have the mime type automatically guessed, please pass `filename` in addition.

  Parameters:

    - obj (file object | `bytes` | `str`) –

      An open file descriptor or the files content as bytes or string.

      Note

      If `obj` is a string, it will be encoded as bytes via `obj.encode('utf-8')`.

      Changed in version 20.0: Accept string input.

    - filename (`str`, optional) – Filename for this InputFile.

    - attach (`bool`, optional) – Pass `True` if the parameter this file belongs to in the request to Telegram should point to the multipart data via an `attach://` URI. Defaults to False.

  input_file_content

    The binary content of the file to send.

    Type:

      `bytes`

  attach_name

    Optional. If present, the parameter this file belongs to in the request to Telegram should point to the multipart data via a an URI of the form `attach://<attach_name>` URI.

    Type:

      `str`

  filename

    Filename for the file to be sent.

    Type:

      `str`

  mimetype

    The mimetype inferred from the file to be sent.

    Type:

      `str`

  property attach_uri

    URI to insert into the JSON data for uploading the file. Returns `None`, if `attach_name` is `None`.

  property field_tuple

    Field tuple representing the contents of the file for upload to the Telegram servers.

    Return type:

      Tuple[`str`, `bytes`, `str`]