From 80be323316df1c31affdd108b59a661297d8d3bd Mon Sep 17 00:00:00 2001 From: Hinrich Mahler <22366557+Bibo-Joshi@users.noreply.github.com> Date: Thu, 24 Nov 2022 13:27:44 +0100 Subject: [PATCH] update download names --- Code-snippets.md | 4 ++-- Local-Bot-API-Server.md | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Code-snippets.md b/Code-snippets.md index 7b9fecd..5a142db 100644 --- a/Code-snippets.md +++ b/Code-snippets.md @@ -361,7 +361,7 @@ When you receive files from a user, you sometimes want to download and save them ```python file_id = message.document.file_id new_file = await bot.get_file(file_id) -await new_file.download() +await new_file.download_to_drive() ``` For a received video/voice/... change `message.document` to `message.video/voice/...`. However, there is one exception: `message.photo` is a *list* of `PhotoSize` objects, which represent different sizes of the same photo. Use `message.photo[-1].file_id` to get the largest size. @@ -370,7 +370,7 @@ Moreover, the above snippet can be shortened by using PTBs built-in utility shor ```python new_file = await message.effective_attachment.get_file() -await new_file.download('file_name') +await new_file.download_to_drive('file_name') ``` `message.effective_attachment` automatically contains whichever media attachment the message has - in case of a photo, you'll again have to use e.g. `message.effective_attachment[-1].get_file()` diff --git a/Local-Bot-API-Server.md b/Local-Bot-API-Server.md index b5218ad..4144db0 100644 --- a/Local-Bot-API-Server.md +++ b/Local-Bot-API-Server.md @@ -13,7 +13,7 @@ Bot API 5.0 (and therefore local API server) is supported by PTB since v13.1. * `base_file_url='your-bot-api-server.com/file/bot'` ### Working with files -* When running the server with the `--local` flag, `get_file` will give you the local file path as `file_path`. PTB detects that, so that `await get_file(…).download()` just returns the local file string instead of downloading it. +* When running the server with the `--local` flag, `get_file` will give you the local file path as `file_path`. PTB detects that, so that `await get_file(…).download_to_drive()` just returns the local file string instead of downloading it. * When running the server with the `--local` flag, you can send files by passing `'file:///absolute/path/to/file'` instead of an URL or a file handle. * Passing relative paths (without prefix) or even passing `pathlib.Path` objects is supported as well, even if you're not running in `local` mode. * When running the server *without* the `--local` flag, the Bot API server does *not* automatically serve the files obtained by `get_file()`. See [telegram-bot-api/#26](https://github.com/tdlib/telegram-bot-api/issues/26). So be aware that you have to run a web server which serves them, otherwise you will run into 404 errors. \ No newline at end of file