# File
URL: /docs/ui/file
Display file message parts with icon, name, size, and download button.
import { FileSample } from "@/components/docs/samples/file";
Getting Started \[#getting-started]
Add file \[#add-file]
Use in your application \[#use-in-your-application]
Pass `File` to `MessagePrimitive.Parts`:
```tsx title="/components/assistant-ui/thread.tsx" {1,8}
import { File } from "@/components/assistant-ui/file";
const AssistantMessage: FC = () => {
return (
);
};
```
Variants \[#variants]
Use the `variant` prop to change the visual style.
```tsx
// Border (default)
// No border
// Background fill
```
Sizes \[#sizes]
Use the `size` prop to change padding and font size.
```tsx
// Compact
// Default
// Larger
```
MimeType Icons \[#mimetype-icons]
The component automatically selects an appropriate icon based on the file's MIME type:
| MIME Type | Icon |
| ------------------ | ------------ |
| `image/*` | ImageIcon |
| `application/pdf` | FileTextIcon |
| `application/json` | BracesIcon |
| `text/*` | FileTextIcon |
| `audio/*` | MusicIcon |
| `video/*` | VideoIcon |
| fallback | FileIcon |
API Reference \[#api-reference]
Composable API \[#composable-api]
The component exports composable sub-components:
```tsx
import {
File,
FileRoot,
FileIconDisplay,
FileName,
FileSize,
FileDownload,
} from "@/components/assistant-ui/file";
report.pdf
```
| Component | Description |
| --------------- | ----------------------------------------------- |
| `File` | Default export, renders complete file part |
| `File.Root` | Container with variant and size styling |
| `File.Icon` | MIME type-aware icon, or pass custom `children` |
| `File.Name` | Truncated filename |
| `File.Size` | Human-readable file size |
| `File.Download` | Download link button |
Custom Icon \[#custom-icon]
Pass `children` to `File.Icon` to override the default MIME type icon:
```tsx
```
Utilities \[#utilities]
The component also exports utility functions:
```tsx
import {
getMimeTypeIcon,
getBase64Size,
formatFileSize,
} from "@/components/assistant-ui/file";
// Get icon component for a MIME type
const Icon = getMimeTypeIcon("application/pdf"); // FileTextIcon
// Calculate size from base64 string
const bytes = getBase64Size("SGVsbG8gV29ybGQh"); // 12
// Format bytes to human-readable
const size = formatFileSize(2048); // "2.0 KB"
```
Related Components \[#related-components]
* [Image](/docs/ui/image) - Image message parts
* [Attachment](/docs/ui/attachment) - File attachments in composer and messages