File Attachments in EJ2 Angular Chat UI component
16 Dec 202515 minutes to read
The Chat UI component supports message attachments, enabling users to upload and send files (images, documents, and more) alongside messages for richer, more contextual conversations. Enable this functionality using the enableAttachments property and customize the behavior through the attachmentSettings configuration.
Enable file attachments
Enable file attachment support by setting the enableAttachments property to true. By default, it is false.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Configure attachment settings
Use the attachmentSettings property to customize file attachment behavior, including upload endpoints, file type restrictions, and size limits.
Setting saveUrl and removeUrl
Set the saveUrl and removeUrl properties to specify server endpoints for handling file uploads and removals. The saveUrl processes file uploads, while the removeUrl handles file deletion requests.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting file type
Use the allowedFileTypes property to specify which file types users can upload. This property accepts file extensions (e.g., ‘.pdf’, ‘.docx’) or MIME types to control the types of files that can be attached.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
allowedFileTypes:'.pdf'
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting file size
Configure the maxFileSize property to define the maximum file size allowed for uploads. Specify the size in bytes. The default value is 30000000 bytes (approximately 30 MB). Files exceeding this limit will not be uploaded.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
maxFileSize:40000000
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting save format
Control the format used to send files to the server using the saveFormat property when path is not set. It does not change how files are uploaded. The default value is Blob.
-
Blob: Used for fast, memory‑efficient local previews. -
Base64: Reads the file as a Base64 data URL, useful when you need an inline data URL.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
saveFormat: 'Base64'
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting server path
The path property specifies the public base URL where uploaded files are (or will be) hosted. When this property is set, it takes precedence over the value defined in saveFormat. This means that even if saveFormat includes a different location or structure for storing files, the path property will be used it for generating the file URL.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
path: 'D:/CustomPathLocation'
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Enabling drag-and-drop
Toggle drag-and-drop support for attachments via enableDragAndDrop property. The default value is true.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
enableDragAndDrop:true
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Setting maximum count
Restrict how many files can be attached at once using maximumCount. The default value is 10. If users select more than the allowed count, the maximum count reached error will be displayed.
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { ChatUIModule } from '@syncfusion/ej2-angular-interactive-chat';
import { UserModel, FileAttachmentSettingsModel } from '@syncfusion/ej2-interactive-chat';
import { UploadingEventArgs } from '@syncfusion/ej2-inputs';
import { Component } from '@angular/core';
@Component({
imports: [ FormsModule, ReactiveFormsModule, ChatUIModule ],
standalone: true,
selector: 'app-root',
// specifies the template string for the Chat UI component
template: `<div id="chatui" ejs-chatui [user]="currentUserModel" [enableAttachments]="enableAttachments" [attachmentSettings]="attachmentSettings"></div>`
})
export class AppComponent {
public currentUserModel: UserModel = { user: 'Albert', id: 'user1' };
public enableAttachments: boolean = true;
public attachmentSettings: FileAttachmentSettingsModel = {
saveUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Save',
removeUrl: 'https://services.syncfusion.com/js/production/api/FileUploader/Remove',
maximumCount:2
};
}import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));Templates
Customizing the file preview
Provide a custom UI for previewing selected files using previewTemplate. Use this to render thumbnails, filenames, progress, remove buttons, or any additional metadata prior to sending.
Customizing the attachments
Control how attachments appear inside message bubbles with attachmentTemplate. Use this to tailor the display of images, documents, or custom file types once the message is posted.