Ark Logo

File Upload

A component that is used to upload multiple files.

    Anatomy

    To set up the file upload component correctly, you'll need to understand its anatomy and how we name its parts.

    Each part includes a data-part attribute to help identify them in the DOM.

    Examples

    Learn how to use the FileUpload component in your project. Let's take a look at the most basic example:

    import { FileIcon } from 'lucide-react'
    import { FileUpload } from '@ark-ui/react'
    
    export const Basic = () => {
      return (
        <FileUpload.Root maxFiles={5}>
          <FileUpload.Label>File Upload</FileUpload.Label>
          <FileUpload.Dropzone>Drag your file(s) here</FileUpload.Dropzone>
          <FileUpload.Trigger>Choose file(s)</FileUpload.Trigger>
          <FileUpload.ItemGroup>
            <FileUpload.Context>
              {({ acceptedFiles }) =>
                acceptedFiles.map((file) => (
                  <FileUpload.Item key={file.name} file={file}>
                    <FileUpload.ItemPreview type="image/*">
                      <FileUpload.ItemPreviewImage />
                    </FileUpload.ItemPreview>
                    <FileUpload.ItemPreview type=".*">
                      <FileIcon />
                    </FileUpload.ItemPreview>
                    <FileUpload.ItemName />
                    <FileUpload.ItemSizeText />
                    <FileUpload.ItemDeleteTrigger>X</FileUpload.ItemDeleteTrigger>
                  </FileUpload.Item>
                ))
              }
            </FileUpload.Context>
          </FileUpload.ItemGroup>
          <FileUpload.HiddenInput />
        </FileUpload.Root>
      )
    }
    

    API Reference

    Root

    PropDefaultType
    accept
    string | Record<string, string[]>

    The accept file types

    allowDrop
    boolean

    Whether to allow drag and drop in the dropzone element

    asChild
    boolean

    Render as a different element type.

    capture
    'user' | 'environment'

    The default camera to use when capturing media

    directory
    boolean

    Whether to accept directories, only works in webkit browsers

    disabled
    boolean

    Whether the file input is disabled

    id
    string

    The unique identifier of the machine.

    ids
    Partial<{ root: string dropzone: string hiddenInput: string trigger: string label: string item(id: string): string itemName(id: string): string itemSizeText(id: string): string itemPreview(id: string): string }>

    The ids of the elements. Useful for composition.

    locale'en-US'
    string

    The current locale. Based on the BCP 47 definition.

    maxFiles
    number

    The maximum number of files

    maxFileSize
    number

    The maximum file size in bytes

    minFileSize
    number

    The minimum file size in bytes

    name
    string

    The name of the underlying file input

    onFileAccept
    (details: FileAcceptDetails) => void

    Function called when the file is accepted

    onFileChange
    (details: FileChangeDetails) => void

    Function called when the value changes, whether accepted or rejected

    onFileReject
    (details: FileRejectDetails) => void

    Function called when the file is rejected

    translations
    IntlTranslations

    The localized messages to use.

    validate
    (file: File) => FileError[] | null

    Function to validate a file

    Dropzone

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    HiddenInput

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    ItemDeleteTrigger

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    ItemGroup

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    ItemName

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    ItemPreviewImage

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    ItemPreview

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    type'.*'
    string

    The file type to match against. Matches all file types by default.

    Item

    PropDefaultType
    file
    File

    asChild
    boolean

    Render as a different element type.

    ItemSizeText

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    Label

    PropDefaultType
    asChild
    boolean

    Render as a different element type.

    Trigger

    PropDefaultType
    asChild
    boolean

    Render as a different element type.