|Kit

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

Loading preview

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".

    PNG, JPG or GIF.

    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.

      A PDF, up to 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.

        An image, up to 1 MB.

        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.

          A PDF, up to 1 MB.

          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.

            Des PDF, 1 Mo maximum chacun.

            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.

                        Up to 3 files, 5 MB each.

                        Drop files here or click to browse

                          Drop files here or click to browse

                          A file is required

                            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.

                            Each file uploads as soon as you drop it.

                            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 / Space opens the file dialog), and drop / drag-over states are announced.
                              • A hidden native <input type="file"> backs form submission; pass name to include it.
                              • Each accepted file is a FileItem row in a list, and its remove button (Ark's delete trigger) has an aria-label (Remove <filename>). With a queue, the button is named Cancel 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 through aria-describedby and aria-errormessage, so it is read out when it appears and again when the dropzone is focused. An app error takes the same slot.
                              • The dropzone is named by the field's label when there is one.
                              • invalid (or error) flips the dropzone to the red state; label / description / error associations are wired via the built-in Field.
                              • testId renders as data-testid on the visible dropzone surface — never the hidden native <input type="file">. See the Testing guide.
                              • RTL is honored via the document dir.

                              Changelog

                              v0.30.0
                              • Form controls follow the disabled and invalid state of an enclosing Field or Fieldset, including dimming and turning red

                                #481
                              v0.20.0
                              • onDrop is removed — it never ran; filter with accept, maxFiles and maxFileSize and read what they turn away in onReject

                                #358
                              • queue={useFileQueue(…)} uploads what's picked with per-row progress, Retry, cancel and one summary announcement (translations.summary)

                                #367
                              • onReject(rejections) reports what accept, maxFiles or maxFileSize turned away, and capture opens the phone camera

                                #358
                              • A rejected file shows why in the error slot ("report.pdf is too large (12.4 MB, max 1 MB)"), reworded through translations.rejected and moreRejected; an error you pass still wins

                                #365
                              • validate, minFileSize, preventDocumentDrop (on by default), color, thumbnails, icons and translations.hint/buttonHint; sizes format in the IntlProvider locale

                                #365
                              • 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

                                #390
                              • The file list is drawn with FileItem

                                #366
                              • The dropzone is named by its label, described by its error, and keeps focus when the first error appears

                                #365
                              • An uploaded SVG thumbnail opened in a new tab can no longer run script as your app

                                #373
                              v0.19.1
                              • A border with no colour class takes the kit's hairline (brand-900/20 in light, white/15 in dark) instead of the text colour, so Timeline bullets and Schedule's time-column divider render as they do in the docs

                                #333
                              v0.19.0
                              • A translations prop for the built-in trigger, clear, remove, search, increment/decrement and upload labels

                                #331
                              v0.17.0
                              • Keep the visually hidden input contained inside the control

                                #265
                              v0.13.0
                              • Reconcile the card border and withBorder dividers to one hairline

                                #193
                              v0.6.0
                              • Inputs drop the filled variant and the color prop

                                #96
                              v0.3.1
                              • Correct dark-mode border shades on Kbd, Notification, FileUpload and ChoiceCardGroup

                                #37
                              v0.0.1
                              • FileUpload

                              On this page