File Upload
A drag-and-drop file picker on Ark UI's FileUpload machine — a dashed dropzone with a browse button, a list of accepted files with thumbnails / sizes / remove, built-in label / description / error, and native form submission.
FileUpload is a drag-and-drop file picker. It renders a dashed dropzone with a browse button, then lists the accepted files as FileItem rows — each with an image thumbnail or a kind icon, name, human-readable size, and a remove button. Drop, click-to-browse, keyboard, and the full ARIA model come from Ark UI's FileUpload machine. It implements the kit's value-based form-control contract — onChange hands you the accepted File[], and name wires the hidden native input into form submission. Label, description, and error are built in via Field.
import { FileUpload } from '@42-central/ui-react/file-upload';
<FileUpload label="Submission" />Playground
Component
Dir
Presets
Props
Code
<Component
maxFiles={1}
size="md"
label="Submission"
/>Multiple files
maxFiles defaults to 1 (single-file). Raise it to accept several at once — each accepted file gets its own row.
Drop files here or click to browse
Restricting types
Gate the picker with accept — a MIME map ({ 'image/*': ['.png', '.jpg'] }) or a glob string ('image/*'). maxFileSize and minFileSize (in bytes) bound each file's size; minFileSize={1} turns away empty files. Files that don't pass never reach onChange, and the dropzone says why (see Rejected files).
<FileUpload label="Avatar" accept="image/*" />
<FileUpload
label="Documents"
accept={{ 'application/pdf': ['.pdf'] }}
maxFileSize={5_000_000}
/>Sizes are shown in decimal units, so 5_000_000 reads "5 MB" while 5 * 1024 * 1024 reads "5.24 MB".
Drop files here or click to browse
Rejected files
A file that accept, maxFiles, maxFileSize, minFileSize or validate turns away never reaches onChange. The dropzone turns red and names it in the field's error slot, where it is tied to the dropzone for screen readers and read out as it appears: "report.pdf is too large (12.4 MB, max 5 MB)." The message clears as soon as a pick goes through. Try a file that isn't a PDF, or one over 1 MB.
Drop files here or click to browse
Code
<FileUpload
label="Report"
description="A PDF, up to 1 MB."
accept="application/pdf"
maxFileSize={1_000_000}
/>Each file is named with its first reason. When several are turned away at once, the first three get a line each and the rest are counted ("2 more files were rejected."). Going over maxFiles is said once for the whole pick ("Only 3 files can be added."), rather than once per file.
Your own message
onReject hands over the rejected files with their reasons as error codes: FILE_INVALID_TYPE, FILE_TOO_LARGE, FILE_TOO_SMALL, TOO_MANY_FILES, FILE_EXISTS, FILE_INVALID, plus any code your validate returns. Turn them into a message and pass it to error: an app's error always replaces the built-in one. onReject fires again with an empty list once a pick goes through, so setting error from it also clears the message.
Drop files here or click to browse
Code
const REASONS: Record<string, string> = {
FILE_INVALID_TYPE: "isn't an image",
FILE_TOO_LARGE: 'is larger than 1 MB',
};
const [error, setError] = useState<string | null>(null);
<FileUpload
label="Avatar"
accept="image/*"
maxFileSize={1_000_000}
error={error}
onReject={(rejections) =>
setError(
rejections
.map(({ file, errors }) => `${file.name} ${REASONS[errors[0]] ?? "can't be used"}.`)
.join(' ') || null,
)
}
/>Custom checks
validate runs alongside the built-in checks and returns the codes that turn a file away (listed after theirs), or null to accept it. Here a PDF is checked by type (accept) and by extension (validate), so a renamed .docx is still refused. Word your own codes with translations.rejected: return undefined for the codes you don't handle, and they keep their English default.
Drop files here or click to browse
Code
const pdfOnly: FileUploadValidate = (file) =>
file.name.toLowerCase().endsWith('.pdf') ? null : ['NOT_A_PDF'];
<FileUpload
label="Signed agreement"
accept="application/pdf"
maxFileSize={1_000_000}
validate={pdfOnly}
translations={{
rejected: (code, { file }) =>
code === 'NOT_A_PDF' ? `${file.name} isn't a PDF.` : undefined,
}}
/>In another language
Every string FileUpload renders goes through translations: the dropzone hint, the browse button, the remove buttons, and one rejected(code, details) line per code. details carries the file, its size, the maxFileSize / minFileSize limits and maxFiles, with sizes already formatted for the IntlProvider locale, the same way the file rows show them ("1,23 Mo" in French). Return null from rejected to show nothing for a code.
Glissez-déposez vos fichiers ici, ou
Code
'use client';
import { IntlProvider } from '@42-central/ui-react';
import { FileUpload, type FileUploadTranslations } from '@42-central/ui-react/file-upload';
const FR: FileUploadTranslations = {
hint: 'Déposez vos fichiers ici ou cliquez pour parcourir',
buttonHint: 'Glissez-déposez vos fichiers ici, ou',
browseFiles: 'Parcourir',
dropzone: 'Zone de dépôt',
deleteFile: (file) => `Retirer ${file.name}`,
itemPreview: (file) => `Aperçu de ${file.name}`,
rejected: (code, { file, size, maxFileSize, minFileSize, maxFiles }) => {
switch (code) {
case 'FILE_INVALID_TYPE':
return `${file.name} n'est pas d'un type accepté.`;
case 'FILE_TOO_LARGE':
return `${file.name} est trop volumineux (${size}, max ${maxFileSize}).`;
case 'FILE_TOO_SMALL':
return `${file.name} est trop petit (${size}, min ${minFileSize}).`;
case 'FILE_EXISTS':
return `${file.name} a déjà été ajouté.`;
case 'TOO_MANY_FILES':
return maxFiles === 1 ? 'Un seul fichier peut être ajouté.' : `${maxFiles} fichiers au maximum.`;
default:
return `${file.name} ne peut pas être utilisé.`;
}
},
moreRejected: (count) =>
count === 1 ? '1 autre fichier a été refusé.' : `${count} autres fichiers ont été refusés.`,
};
<IntlProvider locale="fr-FR">
<FileUpload
label="Justificatifs"
accept="application/pdf"
maxFileSize={1_000_000}
maxFiles={3}
withButton
translations={FR}
/>
</IntlProvider>Thumbnails and icons
Image files show a thumbnail in their row, loaded lazily so rows scrolled out of view aren't decoded. For a picker that takes hundreds of photos at once, thumbnails={false} shows the kind icon instead and makes no object URLs at all.
Thumbnails are safe to open in a tab: a dropped .svg is drawn from a data: URL, never an object URL, which would run its script as your app. FileItem's thumbnails has the details.
<FileUpload label="Event photos" accept="image/*" maxFiles={500} thumbnails={false} />icons replaces the dropzone's upload icon and any of the rows' FileItem icons: one per kind (pdf, spreadsheet, image…) plus remove.
<FileUpload label="Report" icons={{ upload: <FileUp className={iconStroke} aria-hidden /> }} />Phone camera
capture asks a phone for its camera instead of its photo library when the dropzone (or its browse button) is tapped: "environment" for the back camera, "user" for the front one. Desktop browsers ignore it.
<FileUpload label="Receipt" accept="image/*" capture="environment" />With capture, a phone can't pick an existing photo any more. To offer both, use two FileTrigger buttons, "Take photo" and "Choose from library".
Colors
color accents the dropzone while a file is dragged over it, and the browse button. At rest the dropzone is palette-independent, so drag a file over one to see its accent. Without color, it follows the surrounding data-color.
Drag & drop files here, or
Drag & drop files here, or
Drag & drop files here, or
Drag & drop files here, or
Drag & drop files here, or
Code
<FileUpload label="Neutral" color="neutral" withButton />
<FileUpload label="Brand" color="brand" withButton />
<FileUpload label="Green" color="green" withButton />
<FileUpload label="Orange" color="orange" withButton />
<FileUpload label="Red" color="red" withButton />Label, description & error
FileUpload wraps itself in Field, so label / description / error / required work out of the box and wire the aria-* relationships. Passing error flips the dropzone to the invalid (red) state.
Drop files here or click to browse
Drop files here or click to browse
Code
<FileUpload
label="Project files"
description="Up to 3 files, 5 MB each."
maxFiles={3}
/>
<FileUpload label="CV" error="A file is required" />Controlled
Drive the accepted files from state. onChange hands you the File[] whenever the selection changes.
'use client';
import { useState } from 'react';
import { FileUpload } from '@42-central/ui-react/file-upload';
export function AvatarUpload() {
const [files, setFiles] = useState<File[]>([]);
return (
<FileUpload
label="Avatar"
accept="image/*"
value={files}
onChange={setFiles}
/>
);
}Uploading
FileUpload picks files; it doesn't send them. Pass a useFileQueue as queue and each file you drop is uploaded: its row shows the progress, the × cancels while it is in flight, and a failed upload offers Retry. The queue holds the files, so queue replaces value. The demo's uploads are fake, and some fail at random.
Drop files here or click to browse
Code
const queue = useFileQueue({ upload: (file, context) => xhrUpload(url, toFormData(file), context) });
<FileUpload label="Documents" maxFiles={10} queue={queue} />The rows keep quiet while they upload: FileUpload renders the queue's FileQueueSummary, one polite status region that says "Uploading 3 files" when a run starts, names the failures as they happen, and "Upload finished: 2 uploaded, 1 failed" at the end.
The upload strings go through translations too: the rows' under FileItem's keys (cancel, retry, queued, processing, done, failed), and the summary's under summary(event).
Forms
FileUpload renders a hidden native <input type="file">, so a name wires it into native <form> submission and FormData — no controlled state required.
<form action={save}>
<FileUpload name="submission" label="Submission" />
</form>API
Prop
Type
Accessibility
- Built on Ark UI's FileUpload machine: the dropzone is a labelled button (
Enter/Spaceopens the file dialog), and drop / drag-over states are announced. - A hidden native
<input type="file">backs form submission; passnameto include it. - Each accepted file is a
FileItemrow in a list, and its remove button (Ark's delete trigger) has anaria-label(Remove <filename>). With aqueue, the button is namedCancel upload of <filename>while the file is in flight. The rows don't announce: one polite status region, in the page from the first render, says when the upload starts, which files failed, and how it ended, never per file or per progress tick. - A rejected file is named in the field's error slot (
aria-live="polite"), which the dropzone references througharia-describedbyandaria-errormessage, so it is read out when it appears and again when the dropzone is focused. An apperrortakes the same slot. - The dropzone is named by the field's
labelwhen there is one. invalid(orerror) flips the dropzone to the red state; label / description / error associations are wired via the built-inField.testIdrenders asdata-testidon the visible dropzone surface — never the hidden native<input type="file">. See the Testing guide.- RTL is honored via the document
dir.
Changelog
- #481
Form controls follow the
disabledandinvalidstate of an enclosing Field or Fieldset, including dimming and turning red
- #358
onDropis removed — it never ran; filter withaccept,maxFilesandmaxFileSizeand read what they turn away inonReject - #367
queue={useFileQueue(…)}uploads what's picked with per-row progress, Retry, cancel and one summary announcement (translations.summary) - #358
onReject(rejections)reports whataccept,maxFilesormaxFileSizeturned away, andcaptureopens the phone camera - #365
A rejected file shows why in the error slot ("report.pdf is too large (12.4 MB, max 1 MB)"), reworded through
translations.rejectedandmoreRejected; anerroryou pass still wins - #365
validate,minFileSize,preventDocumentDrop(on by default),color,thumbnails,iconsandtranslations.hint/buttonHint; sizes format in theIntlProviderlocale - #390
Error states follow Figma: error text is red-900 in light and red-500 in dark, invalid fields drop the red wash and keep the red border
- #366
The file list is drawn with
FileItem - #365
The dropzone is named by its
label, described by its error, and keeps focus when the first error appears - #373
An uploaded SVG thumbnail opened in a new tab can no longer run script as your app
- #333
A border with no colour class takes the kit's hairline (
brand-900/20in light,white/15in dark) instead of the text colour, so Timeline bullets and Schedule's time-column divider render as they do in the docs
- #331
A
translationsprop for the built-in trigger, clear, remove, search, increment/decrement and upload labels
- #265
Keep the visually hidden input contained inside the control
- #193
Reconcile the card border and withBorder dividers to one hairline
- #96
Inputs drop the
filledvariant and thecolorprop
- #37
Correct dark-mode border shades on Kbd, Notification, FileUpload and ChoiceCardGroup
FileUpload
Pin Input
A row of single-character cells for one-time codes and PINs on Ark UI's PinInput machine — autofocus advance, paste-to-fill, masking, OTP autofill, and native form submission.
FileTrigger
A button that opens the file picker, or a phone's camera, and hands you the picked files. No dropzone and no file list, so any Button or ActionIcon can become one.