Skip to content

feat: [CHA-926] add global file/image upload methods #1564

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 16, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4570,4 +4570,64 @@ export class StreamChat {
...rest,
});
}

/**
* uploadFile - Uploads a file to the configured storage (defaults to Stream CDN)
*
* @param {string|NodeJS.ReadableStream|Buffer|File} uri The file to upload
* @param {string} [name] The name of the file
* @param {string} [contentType] The content type of the file
* @param {UserResponse} [user] Optional user information
*
* @return {Promise<SendFileAPIResponse>} Response containing the file URL
*/
uploadFile(
uri: string | NodeJS.ReadableStream | Buffer | File,
name?: string,
contentType?: string,
user?: UserResponse,
) {
return this.sendFile(`${this.baseURL}/uploads/file`, uri, name, contentType, user);
}

/**
* uploadImage - Uploads an image to the configured storage (defaults to Stream CDN)
*
* @param {string|NodeJS.ReadableStream|File} uri The image to upload
* @param {string} [name] The name of the image
* @param {string} [contentType] The content type of the image
* @param {UserResponse} [user] Optional user information
*
* @return {Promise<SendFileAPIResponse>} Response containing the image URL
*/
uploadImage(
uri: string | NodeJS.ReadableStream | File,
name?: string,
contentType?: string,
user?: UserResponse,
) {
return this.sendFile(`${this.baseURL}/uploads/image`, uri, name, contentType, user);
}

/**
* deleteFile - Deletes a file from the configured storage
*
* @param {string} url The URL of the file to delete
*
* @return {Promise<APIResponse>} The server response
*/
deleteFile(url: string) {
return this.delete<APIResponse>(`${this.baseURL}/uploads/file`, { url });
}

/**
* deleteImage - Deletes an image from the configured storage
*
* @param {string} url The URL of the image to delete
*
* @return {Promise<APIResponse>} The server response
*/
deleteImage(url: string) {
return this.delete<APIResponse>(`${this.baseURL}/uploads/image`, { url });
}
}