update download names

Hinrich Mahler 2022-11-24 13:27:44 +01:00
parent 1aae992e24
commit 80be323316
2 changed files with 3 additions and 3 deletions

@ -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()`

@ -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.