MCPcopy Index your code
hub / github.com/python-telegram-bot/python-telegram-bot / get_file

Method get_file

src/telegram/_bot.py:4065–4133  ·  view source on GitHub ↗

Use this method to get basic info about a file and prepare it for downloading. For the moment, bots can download files of up to :tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD` in size. The file can then be e.g. downloaded with :meth:`telegram.File.down

(
        self,
        file_id: (
            str
            | Animation
            | Audio
            | ChatPhoto
            | Document
            | PhotoSize
            | Sticker
            | Video
            | VideoNote
            | Voice
        ),
        *,
        read_timeout: ODVInput[float] = DEFAULT_NONE,
        write_timeout: ODVInput[float] = DEFAULT_NONE,
        connect_timeout: ODVInput[float] = DEFAULT_NONE,
        pool_timeout: ODVInput[float] = DEFAULT_NONE,
        api_kwargs: JSONDict | None = None,
    )

Source from the content-addressed store, hash-verified

4063 return UserProfilePhotos.de_json(result, self)
4064
4065 async def get_file(
4066 self,
4067 file_id: (
4068 str
4069 | Animation
4070 | Audio
4071 | ChatPhoto
4072 | Document
4073 | PhotoSize
4074 | Sticker
4075 | Video
4076 | VideoNote
4077 | Voice
4078 ),
4079 *,
4080 read_timeout: ODVInput[float] = DEFAULT_NONE,
4081 write_timeout: ODVInput[float] = DEFAULT_NONE,
4082 connect_timeout: ODVInput[float] = DEFAULT_NONE,
4083 pool_timeout: ODVInput[float] = DEFAULT_NONE,
4084 api_kwargs: JSONDict | None = None,
4085 ) -> File:
4086 """
4087 Use this method to get basic info about a file and prepare it for downloading. For the
4088 moment, bots can download files of up to
4089 :tg-const:`telegram.constants.FileSizeLimit.FILESIZE_DOWNLOAD` in size. The file can then
4090 be e.g. downloaded with :meth:`telegram.File.download_to_drive`. It is guaranteed that
4091 the link will be valid for at least 1 hour. When the link expires, a new one can be
4092 requested by calling get_file again.
4093
4094 Note:
4095 This function may not preserve the original file name and MIME type.
4096 You should save the file's MIME type and name (if available) when the File object
4097 is received.
4098
4099 .. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
4100
4101 Args:
4102 file_id (:obj:`str` | :class:`telegram.Animation` | :class:`telegram.Audio` | \
4103 :class:`telegram.ChatPhoto` | :class:`telegram.Document` | \
4104 :class:`telegram.PhotoSize` | :class:`telegram.Sticker` | \
4105 :class:`telegram.Video` | :class:`telegram.VideoNote` | \
4106 :class:`telegram.Voice`):
4107 Either the file identifier or an object that has a file_id attribute
4108 to get file information about.
4109
4110 Returns:
4111 :class:`telegram.File`
4112 """
4113 # Try to get the file_id from the object, if it fails, assume it's a string
4114 with contextlib.suppress(AttributeError):
4115 file_id = file_id.file_id # type: ignore[union-attr]
4116
4117 data: JSONDict = {"file_id": file_id}
4118
4119 result = await self._post(
4120 "getFile",
4121 data,
4122 read_timeout=read_timeout,

Callers 2

msgFunction · 0.45
photoFunction · 0.45

Calls 3

_postMethod · 0.95
is_local_fileFunction · 0.90
de_jsonMethod · 0.45

Tested by

no test coverage detected