Skip to content

Commit 4ecc7cf

Browse files
committed
chore: update docs
1 parent 034c9b5 commit 4ecc7cf

File tree

2 files changed

+44
-4
lines changed

2 files changed

+44
-4
lines changed

docs/fileUpload.md

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,22 @@ console.log('file url: ', response.file);
7272
</html>
7373
```
7474

75-
## Upload progress tracking (axios)
75+
## `axiosRequestConfig` (channel and client uploads)
7676

77-
You can track upload progress by passing axios’s `onUploadProgress` in the optional request config. This works with `client.uploadFile`, `client.uploadImage`, and with `channel.sendFile` / `channel.sendImage`.
77+
Channel uploads use Axios under the hood. Both **`channel.sendFile`** and **`channel.sendImage`** accept an optional **fifth argument** `axiosRequestConfig` (`AxiosRequestConfig` from axios). The same optional argument exists on **`client.uploadFile`** and **`client.uploadImage`**.
78+
79+
The client merges your config **after** its upload defaults (`timeout: 0`, large `maxContentLength` / `maxBodyLength`, and multipart headers from the form data). Any property you set can override or extend those defaults.
80+
81+
Typical uses:
82+
83+
- **`onUploadProgress`** — track bytes sent (see below)
84+
- **`signal`** — pass `AbortSignal` from an `AbortController` to cancel an in-flight upload
85+
- Other Axios per-request options your runtime supports
86+
87+
### Upload progress (`onUploadProgress`)
7888

7989
```js
80-
// Client upload with progress
90+
// client.uploadFile with progress
8191
const response = await client.uploadFile(file, file.name, file.type, undefined, {
8292
onUploadProgress: (progressEvent) => {
8393
const percent = progressEvent.total
@@ -87,7 +97,7 @@ const response = await client.uploadFile(file, file.name, file.type, undefined,
8797
},
8898
});
8999

90-
// Channel sendFile with progress
100+
// channel.sendFile with progress
91101
const response = await channel.sendFile(file, file.name, file.type, undefined, {
92102
onUploadProgress: (progressEvent) => {
93103
const percent = progressEvent.total
@@ -96,6 +106,16 @@ const response = await channel.sendFile(file, file.name, file.type, undefined, {
96106
console.log(`Upload: ${percent}%`);
97107
},
98108
});
109+
110+
// channel.sendImage with progress (same fifth argument)
111+
const imageResponse = await channel.sendImage(file, file.name, file.type, undefined, {
112+
onUploadProgress: (progressEvent) => {
113+
const percent = progressEvent.total
114+
? Math.round((progressEvent.loaded * 100) / progressEvent.total)
115+
: 0;
116+
console.log(`Image upload: ${percent}%`);
117+
},
118+
});
99119
```
100120

101121
## Message composer / attachment manager

src/channel.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,16 @@ export class Channel {
246246
return await this._sendMessage(message, options);
247247
}
248248

249+
/**
250+
* Upload a file to this channel’s file endpoint (multipart). Forwards to the client’s `sendFile` implementation.
251+
*
252+
* @param uri File source: URL string, `File`, `Buffer`, or readable stream (Node).
253+
* @param name File name sent in the multipart body.
254+
* @param contentType MIME type; defaults are applied when omitted.
255+
* @param user Optional user payload appended to the form as JSON.
256+
* @param axiosRequestConfig Optional Axios per-request config, merged after upload defaults (e.g. `onUploadProgress`, `signal` from `AbortController`).
257+
* @return Promise resolving to `{ file: string, ... }` with the CDN URL.
258+
*/
249259
sendFile(
250260
uri: string | NodeJS.ReadableStream | Buffer | File,
251261
name?: string,
@@ -263,6 +273,16 @@ export class Channel {
263273
);
264274
}
265275

276+
/**
277+
* Upload an image to this channel’s image endpoint (multipart). Uses the same transport as `sendFile`.
278+
*
279+
* @param uri Image source: URL string, `File`, or readable stream (Node). For `Buffer` uploads, use `sendFile` toward the channel file endpoint instead.
280+
* @param name File name sent in the multipart body.
281+
* @param contentType MIME type.
282+
* @param user Optional user payload appended to the form as JSON.
283+
* @param axiosRequestConfig Optional Axios per-request config, merged after upload defaults (e.g. `onUploadProgress`, `signal`).
284+
* @return Promise resolving to `{ file: string, ... }` with the CDN URL.
285+
*/
266286
sendImage(
267287
uri: string | NodeJS.ReadableStream | File,
268288
name?: string,

0 commit comments

Comments
 (0)