docs/components/file-upload
Sections
Components
Utilities
Forms
Hooks
Copy Markdown
A component that allows users to upload files.
PreviewCode
Drop files here
or
Browse files You can upload up to 2 files at a time.
CLIManual
pnpmbunnpmyarn
pnpm dlx shadcn@latest add @shark/file-upload
FileUpload
├── FileUploadTrigger
├── FileUploadDropzone
│ ├── FileUploadDropzoneIcon
│ ├── FileUploadTitle
│ ├── FileUploadDescription
│ └── FileUploadHelper
├── FileUploadItemGroup
│ └── FileUploadList
│ └── FileUploadItem
│ ├── FileUploadItemPreview
│ │ └── FileUploadItemPreviewImage
│ ├── FileUploadItemName
│ ├── FileUploadItemSize
│ └── FileUploadItemDeleteTrigger
└── FileUploadClearTrigger
import {
FileUpload,
FileUploadDropzone,
FileUploadDropzoneIcon,
FileUploadTitle,
FileUploadDescription,
FileUploadHelper,
FileUploadTrigger,
FileUploadList,
} from "@/components/ui/file-upload";
<FileUpload maxFiles={2} accept={["image/*png,image/jpeg*", ".pdf"]}>
<FileUploadDropzone>
<FileUploadDropzoneIcon />
<FileUploadTitle>Drop files here</FileUploadTitle>
<FileUploadDescription>or</FileUploadDescription>
<FileUploadTrigger />
<FileUploadHelper>You can upload up to 2 files at a time.</FileUploadHelper>
</FileUploadDropzone>
<FileUploadList />
</FileUpload>
Use the maxFiles prop to allow uploading multiple files at once.
PreviewCode
Drop files here
or
Browse files You can upload up to 5 files at a time.
PreviewCode
Browse files
Use FileUploadDropzone to enable drag-and-drop. It exposes a data-dragging attribute for styling the drag state.
PreviewCode
Drop your files here
Use the accept prop to restrict file types.
PreviewCode
Drop your images here
Only PNG and JPEG formats are allowed.
Use Field to add helper text and error handling.
PreviewCode
Upload images
const { acceptedFiles } = useFileUploadContext();
return (
<div>
{acceptedFiles.map((file) => (
<div key={file.name}>{file.name}</div>
))}
</div>
);
PreviewCode
Drop files here
Use the capture prop to capture and upload media directly from the device camera.
PreviewCode
Take a picture
The capture prop is only supported on mobile devices.
Use the directory prop to upload entire folders.
PreviewCode
Select Folder
Attention: Directory Upload
When uploading directories with many files, set maxFiles to a higher value or remove it entirely to prevent rejections.
Use FileUploadClearTrigger to remove all uploaded files at once.
PreviewCode
Drop files here
Use [--space:--spacing("value")] on FileUploadDropzone to adjust internal spacing.
Default spacing is --spacing(6).
PreviewCode
Drop your files here
You can use breakpoint utilities to change the internal spacing at different screen sizes.
md:[--space:--spacing(6)] lg:[--space:--spacing(8)]
Root component. Manages file state and wraps the upload UI.
| Prop | Type | Default |
|---|---|---|
accept | `string | Record<string, string[]> |
acceptedFiles | File[] | - |
allowDrop | boolean | true |
capture | `"user" | "environment"` |
defaultAcceptedFiles | File[] | - |
directory | boolean | false |
disabled | boolean | - |
invalid | boolean | - |
maxFiles | number | 1 |
maxFileSize | number | Infinity |
minFileSize | number | 0 |
name | string | - |
onFileAccept | (details: FileAcceptDetails) => void | - |
onFileChange | (details: FileChangeDetails) => void | - |
onFileReject | (details: FileRejectDetails) => void | - |
readOnly | boolean | - |
required | boolean | - |
transformFiles | (files: File[]) => Promise<File[]> | - |
validate | `(file: File, details: FileValidateDetails) => FileError[] | null` |
className | string | - |
Opens the native file picker on click.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Drop zone for drag-and-drop. Exposes data-dragging when files are dragged over.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
disableClick | boolean | - |
className | string | - |
| Attribute | Default |
|---|---|
--space | --spacing(8) |
Icon shown in the dropzone.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Title text for the dropzone.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Description or hint for the dropzone.
| Prop | Type | Default |
|---|---|---|
className | string | - |
Small text that provides additional information about the dropzone.
| Prop | Type | Default |
|---|---|---|
className | string | - |
List of uploaded files. Hidden when empty.
| Prop | Type | Default |
|---|---|---|
className | string | - |
List of uploaded files.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
type | `"accepted" | "rejected"` |
className | string | - |
Single uploaded file with preview and remove button.
| Prop | Type | Default |
|---|---|---|
file | File | required |
asChild | boolean | - |
className | string | - |
Preview container for a file.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
type | string | '.*' |
className | string | - |
Image thumbnail for image files. Use inside FileUploadItemPreview with type="image/*".
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Shows the file name.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Shows the formatted file size.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Removes a single file from the list.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Removes all files from the list.
| Prop | Type | Default |
|---|---|---|
asChild | boolean | - |
className | string | - |
Hook to access file upload state and methods. Use inside FileUpload or FileUploadRootProvider.
| Property | Type |
|---|---|
acceptedFiles | File[] |
rejectedFiles | FileRejection[] |
openFilePicker | () => void |
deleteFile | (file: File, type?: ItemType) => void |
clearFiles | () => void |
clearRejectedFiles | () => void |
getFileSize | (file: File) => string |
createFileUrl | (file: File, cb: (url: string) => void) => () => void |
setClipboardFiles | (dt: DataTransfer) => boolean |
For a complete list of props, see the Ark UI documentation.
[
Previous page
Field ](/docs/components/field)[
Next page
Float ](/docs/components/float)
On This Page
InstallationAnatomyUsageExamplesMultiple FilesTrigger onlyDropzone onlyAccepted FilesWith FieldCustom PreviewMedia CaptureDirectory UploadClear TriggerCustom spacingAPI ReferenceFileUploadFileUploadTriggerFileUploadDropzoneFileUploadDropzoneIconFileUploadTitleFileUploadDescriptionFileUploadHelperFileUploadListFileUploadItemGroupFileUploadItemFileUploadItemPreviewFileUploadItemPreviewImageFileUploadItemNameFileUploadItemSizeFileUploadItemDeleteTriggerFileUploadClearTriggeruseFileUploadContext