REFERENCE
SDK Demos
How to use @asgard-js/core and @asgard-js/react, with demos you can try on the page.
File Upload & Drag-and-Drop
<Chatbot> has built-in image and document upload, and users can also drag
and drop files straight onto the chat window. The demo below connects to a
real bot provider, so you can actually pick files, preview them, and drag-drop.
Uploads require a real botProviderEndpoint. In preview mode
(botProviderEndpoint: "skip") the upload buttons still render, but the input
is disabled and files are not uploaded.
The two upload toggles
Prop Shown in the footer Accepted files enableUploadImage upload button JPEG / JPG / PNG / GIF / WebP enableDocumentUploadDocument upload button PDF, Office, CSV, PPT, MP3 / MP4, HTML / XML / TXT / JSON When 3 or more buttons are enabled (including
enableExport), the footer collapses them into a single "+" menu.File limits
Type Allowed formats Per-file limit Count limit Image JPEG / JPG / PNG / GIF / WebP 20MB 10 files Document PDF, Office, CSV, PPT, MP3 / MP4, HTML / XML / TXT / JSON 20MB 10 files Files exceeding the limits are rejected with an error indicator.
Restricting which MIME types can be uploaded
By default all formats in the tables above are accepted. To allow only a subset, pass
allowedImageMimeTypes(withenableUpload) and/orallowedDocumentMimeTypes(withenableDocumentUpload). The demo below runs in preview mode — pick a preset, then open the attachment menu in the chatbot and the file picker will only offer the matching formats:<Chatbot
// ...
enableUpload
enableDocumentUpload
allowedImageMimeTypes={["image/png", "image/jpeg"]} // images: PNG / JPEG only
allowedDocumentMimeTypes={["application/pdf"]} // documents: PDF only
/>How it behaves:
- It overrides, not merges: once provided, it fully replaces the default
list and applies to both the file picker
acceptand upload validation. - You may include types outside the default list, e.g.
["image/svg+xml"]— the values are used as-is. - An empty array is treated as omitted, falling back to the default list.
- ⚠️ Documents are matched differently: when omitted, validation checks the
MIME type or the file extension (some browsers return an empty MIME type);
once
allowedDocumentMimeTypesis set, it matches the MIME type only — no extension fallback, so pass exact MIME types (e.g.application/pdf).
- It overrides, not merges: once provided, it fully replaces the default
list and applies to both the file picker
What gets attached when sending
After a user picks files, the SDK uploads them asynchronously right away and shows a preview above the input (image thumbnails / a document list). When the message is sent, this info is included in
SendMessageParams:Field Description blobIdsBlob ids of successfully uploaded files (both images and documents) filePreviewUrlsLocal preview URLs for images documentNamesOriginal filenames for documents Use
onBeforeSendMessageto read or modify these fields before sending.Code Example
import { Chatbot } from "@asgard-js/react";
export function Demo() {
return (
<Chatbot
title="File Upload Demo"
config={{ botProviderEndpoint: BOT_PROVIDER_ENDPOINT }}
customChannelId="file-upload-demo"
enableUpload
enableDocumentUpload
/>
);
}Customizing drag-and-drop:
useFileDropContextDrag-and-drop is handled by
<Chatbot>out of the box: dragging files over the window shows a drop-zone overlay, and on drop the files are automatically sorted into images / documents and enter the upload flow.If you build a custom footer or want to own the drop zone yourself, use
useFileDropContext:import { useFileDropContext } from "@asgard-js/react";
function CustomDropZone() {
const {
droppedFiles,
isDraggingOver,
setDroppedFiles,
setIsDraggingOver,
clearDroppedFiles,
} = useFileDropContext();
// isDraggingOver: whether the user is dragging files over the window
// droppedFiles: the File[] after a drop
// setDroppedFiles / clearDroppedFiles: inject or clear pending files
return null;
}Field / method Description droppedFilesThe pending dropped File[]isDraggingOverWhether the user is dragging files over the window setDroppedFilesSet pending files programmatically setIsDraggingOverSet the dragging state (for custom overlays) clearDroppedFilesClear pending files See also
- Feature Toggles — toggle
enableUpload/enableExport/enableDocumentUploadtogether - Before Send Message — read
blobIds/documentNamesbefore sending - Custom Footer — wiring upload and drag-drop into your own input row
- Feature Toggles — toggle