---
title: "Attachment Upload"
description: "Free React attachment upload: a dropzone with file, image and audio rows, upload progress, retry, removal and image previews. Framer Motion, shadcn install."
category: "Blocks"
parent: "https://beui.dev/components/blocks/file-upload"
publishedAt: "2026-06-18"
updatedAt: "2026-11-25"
documentation: "https://beui.dev/components/blocks/file-upload/attachment-upload"
markdown: "https://beui.dev/components/blocks/file-upload/attachment-upload.md"
license: "MIT"
---

# Attachment Upload

> Free React attachment upload: a dropzone with file, image and audio rows, upload progress, retry, removal and image previews. Framer Motion, shadcn install.

## Install

```bash
npx shadcn@latest add @beui/attachment-upload
```

## Dependencies

- `@floating-ui/dom`
- `clsx`
- `lucide-react`
- `motion`
- `react`
- `react-dom`
- `tailwind-merge`

## Usage

### Attachment Upload usage

A mixed attachment workspace with a dropzone, staggered file and image rows, animated upload, success, failure, retry and removal feedback, shared-layout image previews, and an audio waveform.

```tsx
"use client";

import { useEffect, useRef, useState } from "react";
import {
  AttachmentUpload,
  type AttachmentUploadItem,
} from "@/components/motion/attachment-upload";

const INITIAL_ITEMS: AttachmentUploadItem[] = [
  {
    id: "brief",
    name: "launch-brief.pdf",
    kind: "file",
    size: 32_400_000,
    href: "data:application/pdf,beUI%20launch%20brief",
    status: "failed",
    error: "Upload failed",
  },
  {
    id: "flowers",
    name: "orange-flowers.jpg",
    kind: "image",
    size: 9_800_000,
    previewUrl:
      "https://images.unsplash.com/photo-1490750967868-88aa4486c946?auto=format&fit=crop&w=1200&q=85",
  },
  {
    id: "voice-note",
    name: "launch-note.m4a",
    kind: "audio",
    currentTime: 12,
    duration: 48,
  },
];

export function AttachmentUploadPreview() {
  const [items, setItems] = useState(INITIAL_ITEMS);
  const [playingId, setPlayingId] = useState<string>();
  const retryTimersRef = useRef<number[]>([]);

  useEffect(
    () => () => {
      for (const timer of retryTimersRef.current) {
        window.clearTimeout(timer);
      }
    },
    [],
  );

  useEffect(() => {
    if (!playingId) return;

    const timer = window.setInterval(() => {
      setItems((current) =>
        current.map((item) => {
          if (item.id !== playingId || !item.duration) return item;
          const nextTime = Math.min(
            item.duration,
            (item.currentTime ?? 0) + 1,
          );
          return { ...item, currentTime: nextTime };
        }),
      );
    }, 1000);

    return () => window.clearInterval(timer);
  }, [playingId]);

  useEffect(() => {
    if (!playingId) return;
    const playingItem = items.find((item) => item.id === playingId);
    if (
      playingItem?.duration &&
      (playingItem.currentTime ?? 0) >= playingItem.duration
    ) {
      setPlayingId(undefined);
    }
  }, [items, playingId]);

  return (
    <div className="w-full max-w-2xl px-3 py-6 sm:px-6">
      <AttachmentUpload
        value={items}
        onValueChange={setItems}
        onRetry={(retryItem) => {
          setItems((current) =>
            current.map((item) =>
              item.id === retryItem.id
                ? { ...item, status: "uploading", error: undefined }
                : item,
            ),
          );

          const completeTimer = window.setTimeout(() => {
            setItems((current) =>
              current.map((item) =>
                item.id === retryItem.id
                  ? { ...item, status: "complete" }
                  : item,
              ),
            );
          }, 900);
          const readyTimer = window.setTimeout(() => {
            setItems((current) =>
              current.map((item) =>
                item.id === retryItem.id
                  ? { ...item, status: "idle" }
                  : item,
              ),
            );
          }, 1900);
          retryTimersRef.current.push(completeTimer, readyTimer);
        }}
        playingId={playingId}
        onAudioToggle={(item) => {
          setPlayingId((current) =>
            current === item.id ? undefined : item.id,
          );
        }}
        attachmentsLabel="Attachments:"
      />
    </div>
  );
}
```

## API Reference

### AttachmentUpload

| Prop | Type | Default | Required | Description |
| --- | --- | --- | --- | --- |
| `value` | `AttachmentUploadItem[]` | — | No | The attachment list, for controlled use. |
| `defaultValue` | `AttachmentUploadItem[]` | — | No | The initial attachment list when uncontrolled. |
| `onValueChange` | `((items: AttachmentUploadItem[]) => void)` | — | No | Called with the full list when attachments are added or removed. |
| `onFilesAdded` | `((items: AttachmentUploadItem[], files: File[]) => void)` | — | No | Called with the new items and their files after files are accepted. |
| `onFilesRejected` | `((files: File[], reason: AttachmentRejectReason) => void)` | — | No | Called with files turned away for being too large or over `maxFiles`. |
| `onRemove` | `((item: AttachmentUploadItem) => void)` | — | No | Called with the item after its remove animation finishes. |
| `onRetry` | `((item: AttachmentUploadItem) => void)` | — | No | Called with a failed item when its retry button is pressed. Shows the button. |
| `playingId` | `string` | — | No | Id of the audio attachment that shows as playing. |
| `onAudioToggle` | `((item: AttachmentUploadItem) => void)` | — | No | Called with an audio item when its play or pause button is pressed. |
| `accept` | `string` | — | No | File types the picker allows, as in the input `accept` attribute. |
| `multiple` | `boolean` | `true` | No | Allows picking or dropping more than 1 file at a time. Default: true |
| `maxFiles` | `number` | `12` | No | Most attachments allowed. The dropzone locks once reached. Default: 12 |
| `maxFileSize` | `number` | `500 * 1024 * 1024` | No | Largest file size allowed, in bytes. Default: 500 MB |
| `disabled` | `boolean` | `false` | No | Turns off the dropzone and file picker. Default: false |
| `title` | `string` | — | No | Heading inside the dropzone. Default: "Drag and drop or browse files" |
| `description` | `string` | — | No | Line under the dropzone heading. Defaults to the max file size. |
| `attachmentsLabel` | `string` | — | No | Heading above the attachment list. Default: "Attachments" |
| `labels` | `Partial<{ title: string; description: string; attachments: string; input: string; limitTitle: string; limitDescription: string; uploading: string; uploadComplete: string; uploadCompleteFor: string; ... 15 more ...; web: string; }>` | — | No | Override any built-in string. `{name}` fills the per-attachment labels; `{count}` and `{max}` fill `limitDescription`; `{size}` fills `description`. |
| `className` | `string` | — | No | Classes merged onto the root element. |
| `classNames` | `AttachmentUploadClassNames` | — | No | Classes for the dropzone, list and each row. |

## Types

### AttachmentUploadItem

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | Unique key for the row in the list. |
| `name` | `string` | Yes | File or link name shown on the row and used in its labels. |
| `kind` | `AttachmentUploadKind` | Yes | Row type: picks the icon, image thumbnail or audio player. |
| `size` | `number` | No | File size in bytes, shown under the name. Hidden for links. |
| `href` | `string` | No | Link opened by the row's open button; also the image source without `previewUrl`. |
| `previewUrl` | `string` | No | Image used for the thumbnail and preview dialog of an `image` row. |
| `currentTime` | `number` | No | Audio playback position in seconds, shown and filled on the waveform. |
| `duration` | `number` | No | Audio length in seconds, shown after the waveform. |
| `status` | `AttachmentUploadStatus` | No | Upload state; `uploading`, `complete` and `failed` change the row. |
| `error` | `string` | No | Message shown when the status is `failed`. Default: "Upload failed" |
| `file` | `File` | No | The picked File, kept for your upload code; the component does not read it. |

### AttachmentUploadClassNames

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `dropzone` | `string` | No | The drop area, a button that also opens the file picker. |
| `list` | `string` | No | The list of attachment rows. |
| `row` | `string` | No | Each attachment row. |

## More in File Upload

- [File Upload Queue](https://beui.dev/components/blocks/file-upload/upload-queue.md)

## Source

- Registry detail: https://beui.dev/r/attachment-upload
- Raw source: https://beui.dev/r/attachment-upload/raw
- GitHub: https://github.com/starc007/ui-components
