Web · Components
FileUpload
File upload area: single and multiple file selection in a drag-and-drop, gallery or single-row layout.
Live example
Preview
Code
Events
- Events appear here when you interact with the preview.
Gallery: photos, full screen preview (←/→, swipe)
Images, Video · Up to 10 MB · Up to 8 files
Profile photo: a single image, Change button
PNG, JPEG, WEBP · Up to 2 MB
Edit form: files on the server and type icons
sozlesme-2026.pdf
471 KB
budget.xlsx
89.1 KB
presentation-october.pptx
5.2 MB
kaynak-code.zip
12 MB
Inline: in compact forms
Import
File upload area: single and multiple file selection in a drag-and-drop, gallery or single-row layout.
- Rules:
accept(type),maxSize/minSize(size),maxFiles(count) andvalidate(your own rule). Files that don't fit are not added; the reason is written under the area with the file name. Drag and drop and paste are checked too. The same file is not added twice. - Preview: Images and videos appear as thumbnails and open full screen on click. Other files are shown with a colored icon by type and the extension (
PDF,XLSX…). Name and size ("1.4 MB") are written for every file. Preview URLs are created only when needed and freed from memory when the file is removed; images load lazily. - Ways to add: click to choose, drag and drop, and paste while the area is focused (a screenshot with Ctrl+V). On mobile,
captureopens the camera directly. - Upload: With
upload, files upload as soon as they are selected: progress bar, queueing, cancel (when the file is removed) and "Try again" are built in. - Form: Without
upload, files enterFormDataundernamevia a hidden native<input type="file">(formData.getAll(name)in server actions). Existing files from the server and uploaded files are submitted as text (valueorid) under the same name, so the server also knows which old files remain.requiredworks with browser validation, and the initial files return when the form is reset. - Mobile: On touch screens the remove buttons are always visible with a 44 px touch target; the "drag and drop" text is not shown. The preview closes with the back button.
For use with a label, description and error message, see FileField.
Examples
Icon by file type: a separate symbol and color for documents, spreadsheets, presentations, PDF, archives, code, images, video and audio, with an extension label below. FileUpload shows it for files that cannot be previewed; you can use it in your own file lists too. It is a server component.
Examples
parseFileSize
functionTurns a FileSize into bytes. NaN for text that cannot be read.
Examples
formatFileSize
functionTurns a byte count into readable text: 1536 → "1,5 KB". The number format follows the given locale.
Examples
fileExtension
functionThe file's extension, lowercase and without the dot ("report.PDF" → "pdf").
acceptsFile
functionDoes the file match one of the accept rules? Same rules as the native <input accept>: an extension (.pdf), a full type (image/png) or a type family (image/*). Without rules every file is accepted. The component calls this itself on drag and drop and paste, since the browser does not check those.
fileKind
functionFinds a file's kind from its MIME type, else from its extension.
isPreviewable
functionCan the file be previewed as an image or video in the browser?
FileIconProps
interfaceProps of the FileIcon component.
| Name | Type | Default | Description |
|---|---|---|---|
name | string | Name of the file; the type and extension label are derived from it. | |
type? | string | undefined | MIME type (e.g. "application/pdf"); checked before the extension if given. | |
showExtension? | boolean | true | Show an extension label (PDF, XLSX) under the icon? |
className? | string | Classes for size and color (e.g. size-10). |
FileUploadStatus
typeUpload state of a file (only when upload is given).
queued: waiting in line (at mostuploadConcurrencyfiles upload at once).uploading: uploading;progressgives the percentage.done: uploaded;valueis what the server returned.error: failed;errorgives the message, and the user can retry.
FileUploadItem
interfaceA file in the FileUpload list.
| Name | Type | Description |
|---|---|---|
id | string | Unique key. Given automatically to newly selected files. |
name | string | Displayed file name. |
size? | number | undefined | Size (bytes). |
type? | string | undefined | MIME type (e.g. "image/png"); the icon and preview are chosen by it. |
url? | string | undefined | Preview or download URL. Given for files on the server (uploaded earlier); previews of newly selected images and videos are created automatically and not written here. |
file? | File | undefined | The file the user selected. Missing for files coming from the server. |
status? | FileUploadStatus | undefined | Upload state; only when upload is given. See FileUploadStatus. |
progress? | number | undefined | Upload percentage (0 – 100). |
error? | string | undefined | Message of the upload error. |
value? | string | undefined | Text submitted in the form for this file: the value returned by upload or the id of a file from the server. If omitted, id is submitted. |
original? | File | undefined | Original file of an edited image/video (with edit). Re-editing starts from here; file is the edited version. |
edits? | MediaEdits | undefined | Applied edits (with edit). See MediaEdits. |
FileUploadEditOptions
interfaceImage and video editing settings: which tools are enabled for which type (MediaEditorTools), whether it opens right after selection, and output settings.
Extends: MediaEditorTools
| Name | Type | Default | Description |
|---|---|---|---|
auto? | boolean | true | Open the editor before adding when images/videos are selected (like WhatsApp). If cancelled, the files are not added. If false, it opens only via the file's "Edit" button. |
output? | MediaEditorOutput | Type, quality and size of edited files. See MediaEditorOutput. |
FileUploadInit
typeFile for value and defaultValue; if id is omitted, the url or name is used. Enough to show files on the server: { name: "contract.pdf", url: "/files/12", size: 48213 }.
| Name | Type | Description |
|---|---|---|
name | string | Displayed file name. |
size? | number | undefined | Size (bytes). |
type? | string | undefined | MIME type (e.g. "image/png"); the icon and preview are chosen by it. |
url? | string | undefined | Preview or download URL. Given for files on the server (uploaded earlier); previews of newly selected images and videos are created automatically and not written here. |
file? | File | undefined | The file the user selected. Missing for files coming from the server. |
status? | FileUploadStatus | undefined | Upload state; only when upload is given. See FileUploadStatus. |
progress? | number | undefined | Upload percentage (0 – 100). |
error? | string | undefined | Message of the upload error. |
value? | string | undefined | Text submitted in the form for this file: the value returned by upload or the id of a file from the server. If omitted, id is submitted. |
original? | File | undefined | Original file of an edited image/video (with edit). Re-editing starts from here; file is the edited version. |
edits? | MediaEdits | undefined | Applied edits (with edit). See MediaEdits. |
id? | string | undefined | Id of the file; generated if omitted. |
Why a file was not added.
FileRejection
interfaceA file that was not added and the reason; reported via onReject.
| Name | Type | Description |
|---|---|---|
file | File | A file that was not added. |
reason | FileRejectionReason | Reason: type, size, count limit, duplicate file or validate. |
message | string | Message shown to the user. |
FileUploadContext
interfaceTools passed to the upload function.
| Name | Type | Description |
|---|---|---|
signal | AbortSignal | Aborted when the user removes the file or the component unmounts; pass it to fetch. |
onProgress | (percent: number) => void | Report the upload percentage (0 – 100); the bar advances. |
FileUploadLayout
typeHow files are shown.
list: a drag-and-drop area with files row by row below it (small preview, name, size, progress). For documents.gallery: square tiles; images and videos appear as covers, and the "Add" tile is at the end of the gallery. For photos.inline: a single row at text box height ("Choose file" and the selected file's name). For compact forms.
FileUploadClassNames
interfaceClasses that can be passed to the parts of FileUpload.
| Name | Type | Description |
|---|---|---|
dropzone? | string | Drag-and-drop area (or the inline box). |
list? | string | File list or gallery grid (e.g. max-h-80 overflow-auto). |
item? | string | Each file row or tile. |
FileUploadProps
interfaceProps of the FileUpload component.
| Name | Type | Default | Description |
|---|---|---|---|
layout? | FileUploadLayout | "list" | Layout. See FileUploadLayout. |
multiple? | boolean | false | Multiple files can be selected. If false, a newly selected file replaces the old one. |
accept? | string | readonly string[] | Accepted types: an extension (.pdf), a MIME type (image/png) or a type family (image/*). A comma-separated string or an array. The file dialog shows only these; drag and drop and paste are checked too. | |
maxSize? | FileSize | Maximum size per file: bytes or "5 MB". See FileSize. | |
minSize? | FileSize | Minimum size per file: bytes or "1 KB". | |
maxFiles? | number | Maximum number of files (with multiple). The add area is hidden when full. | |
validate? | (file: File) => string | null | undefined | false | Your own rule: return the message to show the user if the file is not acceptable, return nothing if it is. | |
value? | readonly FileUploadInit[] | Files when controlled. | |
defaultValue? | readonly FileUploadInit[] | Initial files when uncontrolled; e.g. existing files on the server in an edit form. They return when the form is reset. | |
onValueChange? | (items: FileUploadItem[]) => void | Called when files change (add, remove, upload state). | |
onReject? | (rejections: FileRejection[]) => void | Called when files that break the rules are not added. The messages are already shown under the field; this is for logging or your own notice. | |
upload? | (file: File, context: FileUploadContext) => Promise<unknown> | Uploads files as soon as they are selected. Called for each file; if it returns a string (e.g. the file's URL or id), that string is submitted in the form under name and becomes the item's value. While uploading a progress bar appears, and "Try again" on error; the form is not submitted until uploads finish. If omitted, the files themselves are submitted with the form. | |
uploadConcurrency? | number | 3 | Maximum number of files uploaded at once. |
placeholder? | ReactNode | "Dosya seç" | Main text of the drag-and-drop area. |
hint? | ReactNode | Short info under the area. If omitted, generated from accept, maxSize and maxFiles ("PNG, JPG · Up to 5 MB · Up to 10 files"); hidden with false. | |
icon? | IconProp | Icon of the drag-and-drop area. | |
preview? | boolean | true | Open a full-screen preview when images and videos are clicked? In the preview, move between files with the arrow keys and swiping. |
edit? | boolean | FileUploadEditOptions | Image and video editing: crop, rotate, draw, text, blur, color; for video also range trimming and muting. true enables all tools; an object selects by type and tool (see FileUploadEditOptions). When a single file is selected the single editor opens, and with several the multi editor with a thumbnail strip at the bottom. Each added image/video also gets an "Edit" button; editing is non-destructive (the original file and edits are stored on the item, and reopening continues where you left off). The size limit (maxSize) applies to the edited file, so a long video can be trimmed to fit the limit. | |
capture? | "user" | "environment" | On mobile, opens the camera directly instead of files: front (user) or back (environment). | |
name? | string | Form field name. See "Form" in the component description. | |
form? | string | Id of the form the field belongs to (if outside the form). | |
required? | boolean | The form cannot be submitted without at least one file. | |
disabled? | boolean | Disabled. | |
readOnly? | boolean | Files are shown but cannot be added or removed. | |
id? | string | Id of the select button; <Label htmlFor> binds to it. | |
tooltip? | TooltipProp | Hint shown when hovering the drag-and-drop area. See TooltipProp. | |
className? | string | Classes added to the container. | |
classNames? | FileUploadClassNames | Classes added to the inner parts. | |
effect? | EffectProp | Effect or effects of the drop area (also plays while a file is dragged) (e.g. "beam", ["lift", "glow"]). If omitted, UIProvider appearance.defaults.fileUpload.effect. See BuiltinEffect. | |
aria-label? | string | Screen reader name when there is no visible label. | |
aria-labelledby? | string | Id of the element naming the field. | |
aria-describedby? | string | Id of the element describing the field. FileField sets it itself. | |
aria-invalid? | boolean | "true" | "false" | Show the field as invalid. FileField sets it itself. |
FileSize
typeFile size: a number of bytes or text with a unit ("5 MB", "500KB", "1.5 GB"). Units are base 1024 (1 KB = 1024 bytes).
FileKind
typeKind of a file by how it looks; icons and previews use it.