Introducing PrimeReact v11-alpha 🎉Discover Now

FileUpload

An unstyled file upload component with drag-and-drop, validation, and progress tracking.

Build fully custom file uploaders with complete control over layout, file lists, and drag-and-drop zones.

Drag and drop files here to upload.
basic-demo

Pre-styled Versions

Choose a pre-styled library to use FileUpload with ready-made designs.
For hook-based usage without components, see the Headless API.

Features#

  • Compound component API with sub-components: Root, Content, List, ItemGroup, Item, ItemPreview, ItemInfo, ItemName, ItemSize, Remove
  • Built-in file type and size validation with configurable error messages
  • Drag-and-drop file selection with visual highlight feedback
  • XMLHttpRequest-based upload with progress tracking
  • Custom upload handler support for client-side file processing
  • Separate tracking of pending and uploaded files
  • Composable file item rendering with Item context providing file data to nested sub-components

Usage#

import { FileUpload } from 'primereact/fileupload';
<FileUpload.Root>
    <FileUpload.Content>
        <FileUpload.ItemGroup>
            <FileUpload.Item>
                <FileUpload.ItemPreview />
                <FileUpload.ItemInfo>
                    <FileUpload.ItemName />
                    <FileUpload.ItemSize />
                </FileUpload.ItemInfo>
                <FileUpload.Remove></FileUpload.Remove>
            </FileUpload.Item>
        </FileUpload.ItemGroup>
    </FileUpload.Content>
</FileUpload.Root>

Behavior#

Polymorphic Rendering#

Use as on any sub-component to change the rendered HTML element.

<FileUpload.Root as="section">
    <FileUpload.Content as="main"></FileUpload.Content>
</FileUpload.Root>

Default elements: Root=div, Content=div, List=div, ItemGroup=div, Item=div, ItemPreview=img, ItemInfo=div, ItemName=div, ItemSize=div, Remove=button.

Render Function Children#

Root accepts a render function as children, providing access to the component instance with state, methods, and computed properties.

<FileUpload.Root>
    {(instance) => (
        <>
            <button onClick={instance.choose}>Choose Files</button>
            <button onClick={instance.upload}>Upload</button>
            <FileUpload.Content>
                <FileUpload.ItemGroup>
                    {instance.state.files.map((file, index) => (
                        <FileUpload.Item key={file.name + file.size} file={file} index={index}>
                            <FileUpload.ItemPreview />
                            <FileUpload.ItemInfo>
                                <FileUpload.ItemName />
                                <FileUpload.ItemSize />
                            </FileUpload.ItemInfo>
                            <FileUpload.Remove onClick={() => instance.remove(index)}>Remove</FileUpload.Remove>
                        </FileUpload.Item>
                    ))}
                </FileUpload.ItemGroup>
            </FileUpload.Content>
        </>
    )}
</FileUpload.Root>

Pass Through#

Some parts may not be visible in the preview depending on the component's current state.

Loading...
/* Select a part to see its CSS selector for custom styling */

API#

FileUploadRoot#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadRootInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadRootInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadRootInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadRootPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadRootInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
namestring—
Name of the request parameter to identify the files at backend.
urlstring—
Remote url to upload the files.
multiplebooleanfalse
Used to select multiple files at once from file dialog.
acceptstring—
Pattern to restrict the allowed file types such as "image/*".
disabledbooleanfalse
When present, it specifies that the element should be disabled.
autobooleanfalse
When enabled, upload begins automatically after selection is completed.
maxFileSizenumber—
Maximum file size allowed in bytes.
fileLimitnumber—
Maximum number of files that can be uploaded.
withCredentialsbooleanfalse
Cross-site Access-Control requests should be made using credentials such as cookies, authorization headers or TLS client certificates.
customUploadbooleanfalse
Whether to use the default upload or a manual implementation defined in uploadHandler callback.
invalidFileLimitMessagestring'Maximum number of files exceeded, limit is {0} at most.'
Message to display when number of files to be uploaded exceeds the limit.
invalidFileSizeMessagestring'{0}: Invalid file size, file size should be smaller than {1}.'
Message to display when file size exceeds the limit.
invalidFileTypeMessagestring'{0}: Invalid file type, allowed file types: {1}.'
Message to display when file type is not allowed.
uploadHandler(event: FileUploadHandlerEvent) => void—
Callback to invoke to implement a custom upload.
onSelect(event: FileUploadSelectEvent) => void—
Callback to invoke when files are selected.
onBeforeUpload(event: FileUploadBeforeUploadEvent) => void—
Callback to invoke before file upload begins to customize the request such as post parameters before the files.
onUpload(event: FileUploadUploadEvent) => void—
Callback to invoke when file upload is complete.
onError(event: FileUploadErrorEvent) => void—
Callback to invoke if file upload fails.
onProgress(event: FileUploadProgressEvent) => void—
Callback to invoke on upload progress.
onBeforeSend(event: FileUploadBeforeSendEvent) => void—
Callback to invoke before send for customization such as adding headers.
onClear() => void—
Callback to invoke when files in queue are removed without uploading.
onRemove(event: FileUploadRemoveEvent) => void—
Callback to invoke when a file is removed.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUpload component.

labeltypedescription
rootFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.
contentFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the content's DOM element.
fileListFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file list's DOM element.
fileFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file's DOM element.
fileThumbnailFileUploadRootPassThroughType<HTMLAttributes<HTMLImageElement>>Used to pass attributes to the file thumbnail's DOM element.
fileInfoFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file info's DOM element.
fileNameFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the fileName's DOM element.
fileSizeFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the fileSize's DOM element.
fileActionsFileUploadRootPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file actions' DOM element.
fileRemoveFileUploadRootPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the file remove button's DOM element.

FileUploadContent#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadContentInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadContentInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadContentInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadContentPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadContentInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.
AttributeValue
data-highlight"true" when files are dragged over the zone

Defines passthrough(pt) options of FileUploadContent component.

labeltypedescription
rootFileUploadContentPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

FileUploadList#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadListInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadListInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadListInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadListPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadListInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadList component.

labeltypedescription
rootFileUploadListPassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.
fileListFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file list's DOM element.
fileFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file's DOM element.
fileThumbnailFileUploadListPassThroughType<HTMLAttributes<HTMLImageElement>>Used to pass attributes to the file thumbnail's DOM element.
fileInfoFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file info's DOM element.
fileNameFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the fileName's DOM element.
fileSizeFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the fileSize's DOM element.
fileActionsFileUploadListPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the file actions' DOM element.

FileUploadItemGroup#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemGroupInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemGroupInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemGroupInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemGroupPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemGroupInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItemGroup component.

labeltypedescription
rootFileUploadItemGroupPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

FileUploadItem#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
fileFile—
The file object to display.
indexnumber—
The index of the file in the list.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItem component.

labeltypedescription
rootFileUploadItemPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

FileUploadItemPreview#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemPreviewInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemPreviewInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemPreviewInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemPreviewPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemPreviewInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItemPreview component.

labeltypedescription
rootFileUploadItemPreviewPassThroughType<HTMLAttributes<HTMLImageElement>>Used to pass attributes to the root's DOM element.

FileUploadItemInfo#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemInfoInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemInfoInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemInfoInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemInfoPassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemInfoInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItemInfo component.

labeltypedescription
rootFileUploadItemInfoPassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

FileUploadItemName#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemNameInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemNameInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemNameInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemNamePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemNameInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItemName component.

labeltypedescription
rootFileUploadItemNamePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

FileUploadItemSize#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadItemSizeInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadItemSizeInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadItemSizeInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadItemSizePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadItemSizeInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadItemSize component.

labeltypedescription
rootFileUploadItemSizePassThroughType<HTMLAttributes<HTMLDivElement>>Used to pass attributes to the root's DOM element.

FileUploadRemove#

NameTypeDefault
refRef<unknown>—
The reference to the component instance.
pIfbooleantrue
Whether the component should be rendered.
styleCSSProperties | ((instance?: FileUploadRemoveInstance) => CSSProperties)—
The style to apply to the component.
classNamestring | ((instance?: FileUploadRemoveInstance) => string)—
The class name to apply to the component.
asstring | number | bigint | boolean | ComponentClass<any, any> | FunctionComponent<any> | ReactElement<unknown, string | JSXElementConstructor<any>> | Iterable<ReactNode, any, any> | ReactPortal | Promise<AwaitedReactNode>—
The component type to render.
asChildbooleanfalse
Whether the component should be rendered as a child component.
instanceFileUploadRemoveInstance—
The instance to pass to the component.
ptSafeRecord<FileUploadRemovePassThrough>—
The pass-through props to pass to the component.
ptOptionsPassThroughOptions—
The pass-through options to pass to the component.
unstyledboolean—
Whether the component should be rendered without classes.
dtunknown—
The design token to use for the component.
stylesStylesOptions<ComponentInstance>—
The styles to use for the component.
render(instance: FileUploadRemoveInstance) => ReactNode—
The render function to render the component with instance access.
childrenany—
The children to render. Accepts `React.ReactNode` for static content or a render function `(instance: I) => React.ReactNode` for instance access. Typed as `any` to avoid JSX type errors when used directly in templates.
[key: string]any—
pt-{optionName}-*-—
Pass through attributes for customizing component. For more info, see Pass Through tab.

Defines passthrough(pt) options of FileUploadRemove component.

labeltypedescription
rootFileUploadRemovePassThroughType<HTMLAttributes<HTMLButtonElement>>Used to pass attributes to the root's DOM element.

Accessibility#

Screen Reader#

FileUpload uses a hidden native input[type="file"] element for file selection. The choose button triggers this input programmatically. File thumbnails use role="presentation" to indicate decorative images. Error messages are rendered as visible text for screen reader announcement.

Keyboard Support#

KeyFunction
tabMoves focus between the choose, upload, cancel buttons and file remove buttons.
enter / spaceActivates the focused button. Opens the file dialog when the choose button is focused.