forms
File Upload
A drag-and-drop dropzone and file picker with type, size and count limits, image previews and per-file progress. Copy-paste ready.
Installation
Usage
Anatomy
Good to know
FileUploadonly collects files. Uploading them is up to you: read the list fromonValueChange, or submit the hidden input with a form by passingname.- Files that fail
accept,maxSizeormaxFilesare never added. Each one callsonFileReject(file, reason)with"type","size"or"count", so you can show your own message. - Without
multiple, a new file replaces the current one. acceptuses the native format: MIME types (image/png), wildcards (image/*) and extensions (.pdf). It's checked for dropped files too, since the browser only filters the picker.useFileUpload()gives any child thefiles,addFiles,removeFile,clearFilesandopenFilePickerhelpers, for custom layouts like an avatar or a gallery.- Don't put a
FileUploadTriggerinside aFileUploadDropzone. Both open the picker, so a click would open it twice.
API Reference
FileUpload
FileUploadDropzone
A focusable drop target. Gets data-dragging while files are over it and data-disabled when disabled. Renders an upload icon and "Drop files here or browse" when it has no children.
FileUploadTrigger
A Button (variant="outline" by default) that opens the file picker. Takes all Button props.
FileUploadList
FileUploadItem
Renders a preview, name, size and remove button unless you pass your own children.
Helpers
isFileAccepted(file, accept) and formatFileSize(bytes) are exported too.
Examples
Limits and errors
Images and PDFs only, up to four files of 2 MB each. A rejected file shows why in an alert.
Avatar
A single image with a round preview, built with FileUploadTrigger and useFileUpload.
Message attachments
A paperclip trigger in a composer, with attached files shown as removable chips.
Photo gallery
A grid of image previews with an add tile that disappears at the limit.