docs/snippets/shared/migration-guides/migrate-attachments.mdx
import { Steps, Step } from "fumadocs-ui/components/steps"; import { Callout } from "fumadocs-ui/components/callout";
CopilotKit now supports multimodal attachments — images, audio, video, and documents — through a unified attachments configuration. The new API replaces the image-only upload props with a single, extensible config object that supports custom upload handlers, file size limits, and any file type.
The following props and types are deprecated:
| Deprecated | Replacement |
|---|---|
imageUploadsEnabled | attachments={{ enabled: true }} |
inputFileAccept | attachments={{ accept: "..." }} |
ImageUpload type | Attachment type |
ImageUploadQueue component | AttachmentQueue component |
These deprecated APIs will continue to work until the next major version but will log a warning in development mode. You can suppress warnings by calling suppressDeprecationWarnings() from @copilotkit/react-ui.
attachments API: available from v1.56.0Before:
import { CopilotChat } from "@copilotkit/react-ui";
<CopilotChat imageUploadsEnabled={true} inputFileAccept="image/*" />;
After:
import { CopilotChat } from "@copilotkit/react-ui";
<CopilotChat
attachments={{
enabled: true,
accept: "image/*",
}}
/>;
import { CopilotChat } from "@copilotkit/react-ui";
<CopilotChat
attachments={{
enabled: true,
// accept defaults to "*/*" — all file types
}}
/>;
import { CopilotChat } from "@copilotkit/react-ui";
<CopilotChat
attachments={{
enabled: true,
maxSize: 10 * 1024 * 1024, // 10MB
onUpload: async (file) => {
const url = await uploadToS3(file);
return { type: "url", value: url, mimeType: file.type };
},
}}
/>;
Before:
import { ImageUploadQueue } from "@copilotkit/react-ui";
<ImageUploadQueue images={selectedImages} onRemoveImage={handleRemove} />;
After:
import { AttachmentQueue } from "@copilotkit/react-ui";
<AttachmentQueue
attachments={selectedAttachments}
onRemoveAttachment={handleRemove}
/>;
Run the codemod to automatically rename props, imports, and types:
npx jscodeshift -t https://raw.githubusercontent.com/CopilotKit/CopilotKit/main/codemods/migrate-attachments.ts --parser=tsx --extensions=tsx,ts ./src
The codemod handles:
imageUploadsEnabled / inputFileAccept props → attachments={{ enabled: true, accept: "..." }}import { ImageUploadQueue } → import { AttachmentQueue }import type { ImageUpload } → import type { Attachment }It does NOT transform:
onUpload return type changed — see Before / After)ImageRenderer prop usage (the v2 attachment rendering is a different architecture)After running, verify your app compiles and review the diff for anything the codemod couldn't handle.
Replace `imageUploadsEnabled` and `inputFileAccept` with the `attachments` config object:
```tsx
// Remove these props:
// imageUploadsEnabled={true}
// inputFileAccept="image/*"
// Add this:
attachments={{ enabled: true, accept: "image/*" }}
```
If you want to support all file types (not just images), omit the `accept` field — it defaults to `"*/*"`.
If you imported `ImageUploadQueue` directly:
```tsx
// Before
import { ImageUploadQueue } from "@copilotkit/react-ui";
// After
import { AttachmentQueue } from "@copilotkit/react-ui";
```
Update the component props: `images` → `attachments`, `onRemoveImage` → `onRemoveAttachment`.
If you imported the `ImageUpload` type:
```tsx
// Before
import type { ImageUpload } from "@copilotkit/react-ui";
// After
import type { Attachment } from "@copilotkit/react-ui";
```
Note: the `Attachment` type has a different shape — see [Gotchas](#gotchas) below.
If you are aware of the deprecations but cannot migrate immediately:
```tsx
import { suppressDeprecationWarnings } from "@copilotkit/react-ui";
suppressDeprecationWarnings();
```
Attachment type shape differs from ImageUpload:
// Old: ImageUpload
{ contentType: string; bytes: string }
// New: Attachment
{
type: "image" | "audio" | "video" | "document";
source: { type: "data"; value: string; mimeType: string }
| { type: "url"; value: string; mimeType?: string };
filename?: string;
size?: number;
status: "uploading" | "ready";
metadata?: Record<string, unknown>;
}
The deprecated props and the new attachments prop can coexist in the same codebase during the transition period. If both imageUploadsEnabled and attachments are provided, attachments takes precedence.
The deprecated APIs will be removed in the next major version of CopilotKit.