telegram.InputFile#

class telegram.InputFile(obj, filename=None, attach=False)[source]#

Bases: object

This object represents a Telegram InputFile.

Changed in version 20.0: The former attribute attach was renamed to attach_name.

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[source]#

The binary content of the file to send.

Type

bytes

attach_name[source]#

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[source]#

Filename for the file to be sent.

Type

str

mimetype[source]#

The mimetype inferred from the file to be sent.

Type

str

property attach_uri[source]#

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

property field_tuple[source]#

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

Return type

Tuple[str, bytes, str]

static is_image(stream)[source]#

Check if the content file is an image by analyzing its headers.

Parameters

stream (bytes) – A byte stream representing the content of a file.

Returns

The mime-type of an image, if the input is an image, or None else.

Return type

str | None