Skip to content

Commit 9e20459

Browse files
committed
Update docs.
1 parent 6aa0522 commit 9e20459

File tree

2 files changed

+8
-27
lines changed

2 files changed

+8
-27
lines changed

docs/getting-started/files.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
Telegram supports specifying files in many different formats. In order to
44
accommodate them all, there are multiple structs and type aliases required.
55

6+
All of these types implement the `RequestFileData` interface.
7+
68
| Type | Description |
79
| ------------ | ------------------------------------------------------------------------- |
8-
| `string` | Used as a local path to a file |
10+
| `FilePath` | A local path to a file |
911
| `FileID` | Existing file ID on Telegram's servers |
1012
| `FileURL` | URL to file, must be served with expected MIME type |
1113
| `FileReader` | Use an `io.Reader` to provide a file. Lazily read to save memory. |
1214
| `FileBytes` | `[]byte` containing file data. Prefer to use `FileReader` to save memory. |
1315

14-
## `string`
16+
## `FilePath`
1517

1618
A path to a local file.
1719

1820
```go
19-
file := "tests/image.jpg"
21+
file := tgbotapi.FilePath("tests/image.jpg")
2022
```
2123

2224
## `FileID`

docs/internals/uploading-files.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,14 @@ func (config DocumentConfig) files() []RequestFile {
2828
// there always is a document file, so initialize the array with that.
2929
files := []RequestFile{{
3030
Name: "document",
31-
File: config.File,
31+
Data: config.File,
3232
}}
3333

3434
// We'll only add a file if we have one.
3535
if config.Thumb != nil {
3636
files = append(files, RequestFile{
3737
Name: "thumb",
38-
File: config.Thumb,
38+
Data: config.Thumb,
3939
})
4040
}
4141

@@ -58,7 +58,7 @@ Let's follow through creating a new media group with string and file uploads.
5858
First, we start by creating some `InputMediaPhoto`.
5959

6060
```go
61-
photo := tgbotapi.NewInputMediaPhoto("tests/image.jpg")
61+
photo := tgbotapi.NewInputMediaPhoto(tgbotapi.FilePath("tests/image.jpg"))
6262
url := tgbotapi.NewInputMediaPhoto(tgbotapi.FileURL("https://i.imgur.com/unQLJIb.jpg"))
6363
```
6464

@@ -85,24 +85,3 @@ are all changed into `attach://file-%d`. When collecting a list of files to
8585
upload, it names them the same way. This creates a nearly transparent way of
8686
handling multiple files in the background without the user having to consider
8787
what's going on.
88-
89-
## Library Processing
90-
91-
If at some point in the future new upload types are required, let's talk about
92-
where the current types are used.
93-
94-
Upload types are defined in `configs.go`. Where possible, type aliases are
95-
preferred. Structs can be used when multiple fields are required.
96-
97-
The main usage of the upload types happens in `UploadFiles`. It switches on each
98-
file's type in order to determine how to upload it. Files that aren't uploaded
99-
(file IDs, URLs) are converted back into strings and passed through as strings
100-
into the correct field. Uploaded types are processed as needed (opening files,
101-
etc.) and written into the form using a copy approach in a goroutine to reduce
102-
memory usage.
103-
104-
In addition to `UploadFiles`, there's more processing of upload types in the
105-
`prepareInputMediaParam` and `prepareInputMediaFile` functions. These look at
106-
the `InputMedia` types to determine which files are uploaded and which are
107-
passed through as strings. They only need to be aware of which files need to be
108-
replaced with `attach://` fields.

0 commit comments

Comments
 (0)