File(file_id, file_unique_id, bot=None, file_size=None, file_path=None, **kwargs)¶
This object represents a file ready to be downloaded. The file can be downloaded with
download. It is guaranteed that the link will be valid for at least 1 hour. When the link expires, a new one can be requested by calling getFile.
Maximum file size to download is 20 MB
Unique identifier for this file.
Unique identifier for this file, which is supposed to be the same over time and for different bots. Can’t be used to download or reuse the file.
Optional. File size.
- file_id (
str) – Identifier for this file, which can be used to download or reuse the file.
- file_unique_id (
str) – Unique and the same over time and for different bots file identifier.
- file_size (
int, optional) – Optional. File size, if known.
- file_path (
str, optional) – File path. Use
downloadto get the file.
- bot (
telegram.Bot, optional) – Bot to use with shortcut method.
- **kwargs (
dict) – Arbitrary keyword arguments.
download(custom_path=None, out=None, timeout=None)¶
Download this file. By default, the file is saved in the current working directory with its original filename as reported by Telegram. If the file has no filename, it the file ID will be used as filename. If a
custom_pathis supplied, it will be saved to that path instead. If
outis defined, the file contents will be saved to that object using the
outare mutually exclusive.
- custom_path (
str, optional) – Custom path.
- out (
io.BufferedWriter, optional) – A file-like object. Must be opened for writing in binary mode, if applicable.
- timeout (
float, optional) – If this value is specified, use it as the read timeout from the server (instead of the one specified during creation of the connection pool).
The same object as
outif specified. Otherwise, returns the filename downloaded to.
ValueError– If both
- custom_path (
Download this file and return it as a bytearray.
Parameters: buf (
bytearray, optional) – Extend the given bytearray with the downloaded data.
Returns: The same object as
bufif it was specified. Otherwise a newly allocated