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

Method download_to_drive

src/telegram/_files/file.py:121–225  ·  view source on GitHub ↗

Download this file. By default, the file is saved in the current working directory with :attr:`file_path` as file name. If :paramref:`custom_path` is supplied as a :obj:`str` or :obj:`pathlib.Path`, it will be saved to that path. Note: If :paramref:`cust

(
        self,
        custom_path: FilePathInput | None = None,
        *,
        read_timeout: ODVInput[float] = DEFAULT_NONE,
        write_timeout: ODVInput[float] = DEFAULT_NONE,
        connect_timeout: ODVInput[float] = DEFAULT_NONE,
        pool_timeout: ODVInput[float] = DEFAULT_NONE,
    )

Source from the content-addressed store, hash-verified

119 return decrypt(b64decode(self._credentials.secret), b64decode(self._credentials.hash), buf)
120
121 async def download_to_drive(
122 self,
123 custom_path: FilePathInput | None = None,
124 *,
125 read_timeout: ODVInput[float] = DEFAULT_NONE,
126 write_timeout: ODVInput[float] = DEFAULT_NONE,
127 connect_timeout: ODVInput[float] = DEFAULT_NONE,
128 pool_timeout: ODVInput[float] = DEFAULT_NONE,
129 ) -> Path:
130 """
131 Download this file. By default, the file is saved in the current working directory with
132 :attr:`file_path` as file name. If :paramref:`custom_path` is supplied as a :obj:`str` or
133 :obj:`pathlib.Path`, it will be saved to that path.
134
135 Note:
136 If :paramref:`custom_path` isn't provided and :attr:`file_path` is the path of a
137 local file (which is the case when a Bot API Server is running in local mode), this
138 method will just return the path.
139
140 The only exception to this are encrypted files (e.g. a passport file). For these, a
141 file with the prefix `decrypted_` will be created in the same directory as the
142 original file in order to decrypt the file without changing the existing one
143 in-place.
144
145 .. seealso:: :wiki:`Working with Files and Media <Working-with-Files-and-Media>`
146
147 .. versionchanged:: 20.0
148
149 * :paramref:`custom_path` parameter now also accepts :class:`pathlib.Path` as argument.
150 * Returns :class:`pathlib.Path` object in cases where previously a :obj:`str` was
151 returned.
152 * This method was previously called ``download``. It was split into
153 :meth:`download_to_drive` and :meth:`download_to_memory`.
154
155 .. versionchanged:: 21.7
156 Raises :exc:`RuntimeError` if :attr:`file_path` is not set. Note that files without
157 a :attr:`file_path` could never be downloaded, as this attribute is mandatory for that
158 operation.
159
160 Args:
161 custom_path (:class:`pathlib.Path` | :obj:`str` , optional): The path where the file
162 will be saved to. If not specified, will be saved in the current working directory
163 with :attr:`file_path` as file name or the :attr:`file_id` if :attr:`file_path`
164 is not set.
165
166 Keyword Args:
167 read_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
168 :paramref:`telegram.request.BaseRequest.post.read_timeout`. Defaults to
169 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
170 write_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
171 :paramref:`telegram.request.BaseRequest.post.write_timeout`. Defaults to
172 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
173 connect_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
174 :paramref:`telegram.request.BaseRequest.post.connect_timeout`. Defaults to
175 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.
176 pool_timeout (:obj:`float` | :obj:`None`, optional): Value to pass to
177 :paramref:`telegram.request.BaseRequest.post.pool_timeout`. Defaults to
178 :attr:`~telegram.request.BaseRequest.DEFAULT_NONE`.

Callers 15

test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_get_and_downloadMethod · 0.80
test_downloadMethod · 0.80

Calls 5

_get_encoded_urlMethod · 0.95
_prepare_decryptMethod · 0.95
is_local_fileFunction · 0.90
retrieveMethod · 0.80
get_botMethod · 0.80

Tested by 15

test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_get_and_downloadMethod · 0.64
test_downloadMethod · 0.64