Docs

Documentation versions (currently viewingVaadin 25.1 (pre-release))

File Attachments

Enable file uploads in the AIOrchestrator to send attachments to the LLM with user prompts.

Enable file uploads by passing an UploadManager, Upload, or any custom AIFileReceiver implementation to the builder via withFileReceiver(). Uploaded files are sent to the LLM as attachments with the next prompt.

Source code
Java
var uploadManager = new UploadManager(this);
var uploadButton = new UploadButton(uploadManager);

var orchestrator = AIOrchestrator
        .builder(provider, systemPrompt)
        .withMessageList(messageList)
        .withInput(messageInput)
        .withFileReceiver(uploadManager)
        .build();
Note
Upload Handler Conflict
When using UploadManager or Upload, the component must not already have an upload handler or receiver set. The orchestrator installs its own in-memory handler. If one is already set, an IllegalArgumentException is thrown at build time. This restriction does not apply to custom AIFileReceiver implementations.
Note
Supported Attachment Types
The following MIME type categories are supported: images (image/), text (text/), PDF (application/pdf), audio (audio/), and video (video/). Attachments with other MIME types are silently dropped and not sent to the LLM.
Note
Duplicate File Names
Uploading multiple files with the same name in a single batch throws an IllegalArgumentException. Ensure each file has a unique name.

To persist attachment data externally (since attachments are not stored in the conversation history), use the withAttachmentSubmitListener() and withAttachmentClickListener() callbacks:

Source code
Java
var orchestrator = AIOrchestrator
        .builder(provider, systemPrompt)
        .withMessageList(messageList)
        .withInput(messageInput)
        .withFileReceiver(uploadManager)
        .withAttachmentSubmitListener(event -> {
            // Store attachments keyed by message ID
            saveAttachments(event.getMessageId(),
                    event.getAttachments());
        })
        .withAttachmentClickListener(event -> {
            // Retrieve and display the attachment
            showAttachment(event.getMessageId(),
                    event.getAttachmentIndex());
        })
        .build();