AIChatUploadFileInfo Class
Contains information about a file to be uploaded to a chat message.
Namespace: DevExpress.AIIntegration.Blazor.Chat
Assembly: DevExpress.AIIntegration.Blazor.Chat.v26.1.dll
Declaration
public class AIChatUploadFileInfo :
IAIChatMessageContextItem
Remarks
Use the MessageSendingEventArgs.Files argument property in a MessageSending event handler to obtain information about files attached to the message.
<DxAIChat MessageSending="OnMessageSending"
FileUploadEnabled="true" />
@code {
async Task OnMessageSending(MessageSendingEventArgs args) {
var fileNames = args.Files.Select(x => x.Name);
var response = $"Processed message content: {args.Content}.{System.Environment.NewLine}";
response += $"The message contains {args.Files.Count} attached file(s):{System.Environment.NewLine}";
response += string.Join(System.Environment.NewLine, fileNames);
await args.Chat.SendMessageAsync(response);
}
}
You can also use AIChatUploadFileInfo class instances in the BlazorChatMessage.Files property and the DxAIChat.SendMessageAsync method.
<DxAIChat @ref="Chat" FileUploadEnabled="true" />
<DxButton Text="Send Message to Chat" Click="SendSampleMessage" />
@code {
DxAIChat Chat { get; set; }
public async Task SendSampleMessage() {
string messageText = "What is on the image?";
byte[] imageBytes = await File.ReadAllBytesAsync(@"C:\Resources\AlbertEinstein.jpg");
var files = new List<AIChatUploadFileInfo>() {
new AIChatUploadFileInfo(
"cat.jpeg",
"image/jpeg",
imageBytes.Length,
imageBytes)
};
await Chat.SendMessageAsync(messageText,
files.Cast<IAIChatMessageContextItem>().ToList());
}
}

Supported File Types
The DevExpress Blazor AI Chat component allows users to upload files, which are then processed and interpreted by the connected AI model. The ability to understand a specific file format is a function of the selected Large Language Model (LLM), not the chat component. If the model does not support the uploaded file’s format, it will be unable to extract file content and will ignore it in responses. Check the specific LLM’s documentation to understand its file handling capabilities:
Some models understand multiple file formats, while others may be more limited. Therefore, for the file upload feature to be effective, the chosen LLM must be compatible with the file type uploaded by the user. To ensure compatibility between user-uploaded files and model capabilities, it is important to specify allowed file types. You can use the AllowedFileExtensions property to restrict uploads by file extension. Additionally, you can specify file types available for selection in the file dialog using the FileTypeFilter option.
If you need to support a file type that the selected AI model cannot natively handle, implement a manual pre-conversion step:
- Intercept the file upload.
- Decode file content to a supported format or extract it as plain text.
- Pass the converted content to the model for analysis.
The following code snippet extracts text from a Word or text file and passes it to the AI model as a chat message:
public class FilesToContextChatClient(IChatClient client) :
DelegatingChatClient(client) {
private IEnumerable<Microsoft.Extensions.AI.ChatMessage> ConvertDataFilesToTextContent(
IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages) {
var result = new List<Microsoft.Extensions.AI.ChatMessage>();
foreach(var item in messages) {
for(int i = 0; i < item.Contents.Count; i++) {
if(item.Contents[i] is DataContent dataContent) {
switch(dataContent.MediaType) {
case "application/vnd.openxmlformats-officedocument.wordprocessingml.document":
item.Contents.Remove(dataContent);
string resultFileContent = string.Empty;
var data = dataContent.Data;
MemoryStream stream = new MemoryStream(data.ToArray());
stream.Seek(0, SeekOrigin.Begin);
using(var wordProcessor = new RichEditDocumentServer()) {
wordProcessor.LoadDocument(stream, DocumentFormat.Docx);
resultFileContent = wordProcessor.Document.Text;
}
result.Add(new Microsoft.Extensions.AI.ChatMessage(ChatRole.System,
"FileDATA: " + resultFileContent));
break;
case "text/plain":
item.Contents.Remove(dataContent);
string txtContent = Encoding.UTF8.GetString(dataContent.Data.ToArray());
result.Add(new Microsoft.Extensions.AI.ChatMessage(ChatRole.System,
"FileDATA: " + txtContent));
break;
default:
break;
}
}
}
result.Add(item);
}
return result;
}
public override Task<ChatResponse> GetResponseAsync(
IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages,
ChatOptions options = null,
CancellationToken cancellationToken = default) {
return base.GetResponseAsync(ConvertDataFilesToTextContent(messages),
options,
cancellationToken);
}
public override IAsyncEnumerable<ChatResponseUpdate> GetStreamingResponseAsync(
IEnumerable<Microsoft.Extensions.AI.ChatMessage> messages,
ChatOptions options = null,
CancellationToken cancellationToken = default) {
return base.GetStreamingResponseAsync(ConvertDataFilesToTextContent(messages),
options,
cancellationToken);
}
}
You can extend the code to support additional formats such as Excel, PDF, and archives. To extract content from these files, use Office & PDF File API or similar libraries.
Note
The size of an uploaded file, regardless of its format, affects performance and cost because large files increase token consumption. To control this, use the MaxFileSize property to restrict the upload size for the DxAIChat component.