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
76
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
Copy file name to clipboardExpand all lines: src/channel.ts
+20Lines changed: 20 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -246,6 +246,16 @@ export class Channel {
246
246
returnawaitthis._sendMessage(message,options);
247
247
}
248
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
+
*/
249
259
sendFile(
250
260
uri: string|NodeJS.ReadableStream|Buffer|File,
251
261
name?: string,
@@ -263,6 +273,16 @@ export class Channel {
263
273
);
264
274
}
265
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