all repos — telegram-bot-api @ 1a3364aea80373adbdfde143541ebe265cc57b93

Golang bindings for the Telegram Bot API

docs/getting-started/files.md (view raw)

 1# Files
 2
 3Telegram supports specifying files in many different formats. In order to
 4accommodate them all, there are multiple structs and type aliases required.
 5
 6| Type         | Description                                                               |
 7| ------------ | ------------------------------------------------------------------------- |
 8| `string`     | Used as a local path to a file                                            |
 9| `FileID`     | Existing file ID on Telegram's servers                                    |
10| `FileURL`    | URL to file, must be served with expected MIME type                       |
11| `FileReader` | Use an `io.Reader` to provide a file. Lazily read to save memory.         |
12| `FileBytes`  | `[]byte` containing file data. Prefer to use `FileReader` to save memory. |
13
14## `string`
15
16A path to a local file.
17
18```go
19file := "tests/image.jpg"
20```
21
22## `FileID`
23
24An ID previously uploaded to Telegram. IDs may only be reused by the same bot
25that received them. Additionally, thumbnail IDs cannot be reused.
26
27```go
28file := tgbotapi.FileID("AgACAgIAAxkDAALesF8dCjAAAa_…")
29```
30
31## `FileURL`
32
33A URL to an existing resource. It must be served with a correct MIME type to
34work as expected.
35
36```go
37file := tgbotapi.FileURL("https://i.imgur.com/unQLJIb.jpg")
38```
39
40## `FileReader`
41
42Use an `io.Reader` to provide file contents as needed. Requires a filename for
43the virtual file.
44
45```go
46var reader io.Reader
47
48file := tgbotapi.FileReader{
49    Name: "image.jpg",
50    Reader: reader,
51}
52```
53
54## `FileBytes`
55
56Use a `[]byte` to provide file contents. Generally try to avoid this as it
57results in high memory usage. Also requires a filename for the virtual file.
58
59```go
60var data []byte
61
62file := tgbotapi.FileBytes{
63    Name: "image.jpg",
64    Bytes: data,
65}
66```