Dosu LogoDosu Logo
Ask
Join our Discord
assistant-ui's SpacePublic
assistant-ui
Documentsassistant-ui's Space
file
file
Type
External
Status
Published
Created
Mar 17, 2026
Updated
Aug 13, 2026
Updated by
Dosu Bot
Source
apps/docs/content/docs/ui/file.mdx

import { FileSample } from "@/components/docs/samples/file";

Getting Started#

Add file#

<InstallCommand shadcn={["file"]} />

Use in your application#

The shipped Thread component renders file parts through File by default, in both assistant and user messages. In a custom thread, pass File to MessagePrimitive.Parts:

import { File } from "@/components/assistant-ui/file";

const UserMessage: FC = () => {
  return (
    <MessagePrimitive.Root className="...">
      <MessagePrimitive.Parts>
        {({ part }) => {
          if (part.type === "file") return <File {...part} />;
          return null;
        }}
      </MessagePrimitive.Parts>
    </MessagePrimitive.Root>
  );
};

Variants#

Use the variant prop to change the visual style.

<File.Root variant="outline" /> // Border (default)
<File.Root variant="ghost" /> // No border
<File.Root variant="muted" /> // Background fill

Sizes#

Use the size prop to change padding and font size.

<File.Root size="sm" /> // Compact
<File.Root size="default" /> // Default
<File.Root size="lg" /> // Larger

MimeType Icons#

The component automatically selects an appropriate icon based on the file's MIME type:

MIME TypeIcon
image/*ImageIcon
application/pdfFileTextIcon
application/jsonBracesIcon
text/*FileTextIcon
audio/*MusicIcon
video/*VideoIcon
fallbackFileIcon

API Reference#

Composable API#

The component exports composable sub-components:

import {
  File,
  FileRoot,
  FileIconDisplay,
  FileName,
  FileSize,
  FileDownload,
} from "@/components/assistant-ui/file";

<FileRoot variant="muted" size="lg">
  <FileIconDisplay mimeType="application/pdf" />
  <div className="flex flex-col gap-0.5">
    <FileName>report.pdf</FileName>
    <FileSize bytes={2048} className="text-xs" />
  </div>
  <FileDownload
    data="SGVsbG8gV29ybGQh"
    mimeType="application/pdf"
    filename="report.pdf"
  />
</FileRoot>
ComponentDescription
FileDefault export, renders complete file part
File.RootContainer with variant and size styling
File.IconMIME type-aware icon, or pass custom children
File.NameTruncated filename
File.SizeHuman-readable file size
File.DownloadDownload link button; renders nothing without a browser-resolvable target (sourceType: "id", urls that are not http(s)/blob/data)

Custom Icon#

Pass children to File.Icon to override the default MIME type icon:

<File.Icon>
  <MyCustomIcon className="size-5" />
</File.Icon>

Utilities#

The component also exports utility functions:

import {
  getMimeTypeIcon,
  getFileDataKind,
  getBase64Size,
  formatFileSize,
} from "@/components/assistant-ui/file";

// Get icon component for a MIME type
const Icon = getMimeTypeIcon("application/pdf"); // FileTextIcon

// Classify the data field of a file part; a declared sourceType wins over sniffing, except a data: payload declared as "url"
const kind = getFileDataKind("https://example.com/report.pdf"); // "url"
const ref = getFileDataKind("file-abc123", "id"); // "id"

// Calculate size from base64 string
const bytes = getBase64Size("SGVsbG8gV29ybGQh"); // 12

// Format bytes to human-readable
const size = formatFileSize(2048); // "2.0 KB"

Related Components#

  • Image - Image message parts
  • Attachment - File attachments in composer and messages
Documents
AG-UI Message History Management
CHANGELOG
CHANGELOG
CHANGELOG
external-store
overview
README
AG-UI Streaming State Management
hooks
index
introduction
overview
part-1
README
README
stockbroker
AI SDK Integration
ai-sdk
assistant-runtime-provider
expo
hooks
index
index
index
introduction
migration
migration
overview
part-2
README
README
README
README
README
README
README
README
stockbroker
Cloud Message Pagination
index
Generative UI Date and Time Controls
In-Memory Thread Lifecycle
CHANGELOG
CHANGELOG
CHANGELOG
Local Runtime Message History
CHANGELOG
Markdown Preprocessing and Repair
CHANGELOG
CHANGELOG
MCP App Tool UI Rendering
CHANGELOG
CHANGELOG
message
MCP OAuth State Management
MessageRepository Branch Pointer Invariant
Next.js Cache Components
Remote Thread List Runtime
adapters
CHANGELOG
CHANGELOG
hooks
index
README
README
thread-runtime
Render Prop Leakage
Run Cancellation and Abort Signal Propagation
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
README
Run Telemetry Model ID Extraction
SSR-Safe Thread ID Generation
Stream Decoder Buffer Limits
CHANGELOG
CHANGELOG
StreamdownTextPrimitive
index
Streaming Markdown Rendering
CHANGELOG
CHANGELOG
index
introduction
part-1
AGENTS
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CHANGELOG
CODE_OF_CONDUCT
CONTRIBUTING
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README
README_LANGGRAPH
SECURITY
SPEC
SPEC_AssistantFrame
SPEC_ModelContextRegistry
action-bar
action-bar-more
adapters
artifacts
assistant-if
assistant-modal
assistant-modal
assistant-runtime
assistant-sidebar
attachment
attachment
attachment-runtime
branch-picker
chatgpt
claude
composer
composer-runtime
composition
context-display
custom-backend
custom-backend
error
file
form-demo
grok
heat-graph
hooks
image
index
index
index
index
index
index
index
index
index
markdown
mem0
mermaid
message-part
message-part-runtime
message-runtime
message-timing
modal
model-selector
part-3
perplexity
pick-a-runtime
primitives
primitives
quote
reasoning
selection-toolbar
sources
suggestion
syntax-highlighting
thread
thread
thread-list
thread-list
thread-list-item
thread-list-item-more
thread-list-item-runtime
thread-list-runtime
tool-fallback
tool-group
tw-shimmer
v4-legacy
v5-legacy