File Upload
File Upload manages file presentation and reports additions, removal and retry intent.
Practical React example
Queue selected files and show progress supplied by the real upload process.
Before you copy and paste
Keep the example in the React rendering environment required by the imported component. Copy components/motion/file-upload.tsx and its returned support files from the Code tab; preserve the project-relative paths.
Listed package dependencies: clsx, lucide-react, motion, react, react-dom, tailwind-merge.
Use the Code tab for the component files and installation instructions, then adapt the imports in this example to your project.
Queue selected files and show progress supplied by the real upload process
// Usage adapted from beUI's pinned MIT source.
// Copyright (c) 2026 Saurabh Chauhan. See ./LICENSES.md.
"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>
);
}
Usage example adapted from beUI's pinned MIT source. Retain the source licence notices when copying.
Use onFilesAdded to start your authorized upload flow, then update item progress and status from that flow. Keep the original File only as long as the client needs it.
Customization
- FileUploadProps.value
- Optional; FileUploadItem[].
- FileUploadProps.defaultValue
- Optional; FileUploadItem[].
- FileUploadProps.onValueChange
- Optional; (items: FileUploadItem[]) => void.
- FileUploadProps.onFilesAdded
- Optional; (items: FileUploadItem[], files: File[]) => void.
- FileUploadProps.onRemove
- Optional; (item: FileUploadItem) => void.
- FileUploadProps.onRetry
- Optional; (item: FileUploadItem) => void.
- FileUploadProps.accept
- Optional; string.
- FileUploadProps.multiple
- Optional; boolean.
- FileUploadProps.maxFiles
- Optional; number.
- FileUploadProps.disabled
- Optional; boolean.
- FileUploadProps.variant
- Optional; FileUploadVariant.
- FileUploadProps.title
- Optional; string.
- FileUploadProps.description
- Optional; string.
- FileUploadProps.browseLabel
- Optional; string.
Integration notes
- Validate file content, size and access on the server; accept and maxFiles are not security controls.
- Cancel or reconcile the underlying upload when removing an uploading item.
Component source: beUI documentation . These examples describe the version imported into Rendyn. Upstream APIs may have changed; retain the source licence notices when adapting the code.
Give your agent taste.
The best way to use Rendyn is through MCP. Let your agent find the right component, compare previews and bring the source into your project.
All components are free. Sign up only to connect MCP.