You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## `axiosRequestConfig` (channel and client uploads)
76
+
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
When using the message composer’s attachment manager, upload progress is tracked when `config.attachments.trackUploadProgress` is `true` (the default). Progress is stored on each attachment’s `localMetadata.uploadProgress` (0–100 for the default upload path, from the axios progress event; the initial state is 0% when the upload starts).
124
+
125
+
With a custom `doUploadRequest`, the function receives an optional second argument `options` with `onProgress?: (percent: number | undefined) => void`. Call `onProgress` from your upload implementation to drive the same `localMetadata.uploadProgress` updates. If you do not call it, `uploadProgress` stays at 0 until the upload finishes.
126
+
127
+
Set `trackUploadProgress` to `false` to skip setting `uploadProgress` (will be `undefined` in this case) and to omit progress callbacks to both the default channel upload and custom `doUploadRequest`.
Copy file name to clipboardExpand all lines: src/channel.ts
+25Lines changed: 25 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -1,3 +1,4 @@
1
+
importtype{AxiosRequestConfig}from'axios';
1
2
import{ChannelState}from'./channel_state';
2
3
import{CooldownTimer}from'./CooldownTimer';
3
4
import{MessageComposer}from'./messageComposer';
@@ -245,33 +246,57 @@ export class Channel {
245
246
returnawaitthis._sendMessage(message,options);
246
247
}
247
248
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
+
*/
248
259
sendFile(
249
260
uri: string|NodeJS.ReadableStream|Buffer|File,
250
261
name?: string,
251
262
contentType?: string,
252
263
user?: UserResponse,
264
+
axiosRequestConfig?: AxiosRequestConfig,
253
265
){
254
266
returnthis.getClient().sendFile(
255
267
`${this._channelURL()}/file`,
256
268
uri,
257
269
name,
258
270
contentType,
259
271
user,
272
+
axiosRequestConfig,
260
273
);
261
274
}
262
275
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.
0 commit comments