Skip to main content
Upload field components provide file upload functionality with preview and management features.

ProFormUploadButton

Button-style upload component for file uploads.

Import

import { ProFormUploadButton } from '@ant-design/pro-components';

Usage

<ProFormUploadButton
  name="attachments"
  label="Attachments"
  title="Click to Upload"
  action="/api/upload"
  max={5}
/>

Props

Extends ProFormText props and Ant Design Upload props.
action
string
Upload endpoint URL. Required unless using customRequest.
title
ReactNode
default:"'Click to Upload'"
Text displayed on the upload button.
icon
ReactNode
default:"<UploadOutlined />"
Icon displayed on the upload button.
max
number
Maximum number of files allowed. When limit is reached, upload button becomes disabled.
accept
string
Accepted file types. Uses HTML input accept attribute:
  • image/*: All image types
  • image/png,image/jpeg: Specific image types
  • .pdf,.doc,.docx: File extensions
  • video/*,audio/*: Multiple media types
listType
'text' | 'picture' | 'picture-card' | 'picture-circle'
default:"'picture'"
Upload list display style:
  • text: Show as text list with file icon
  • picture: Show as list with thumbnail
  • picture-card: Show as card grid with large thumbnail
  • picture-circle: Show as circular thumbnails
buttonProps
ButtonProps
Props passed to the upload button. Accepts all Ant Design Button props:
buttonProps={{
  type: 'primary',
  size: 'large',
  danger: true
}}
disabled
boolean
default:"false"
Whether the upload button is disabled.
imageProps
Omit<ImageProps, 'src'>
Props for image preview component. Accepts Ant Design Image props:
imageProps={{
  preview: {
    toolbarRender: () => null,
    maskClassName: 'custom-mask'
  }
}}
value
UploadFile[]
Controlled file list value. File object structure:
interface UploadFile {
  uid: string;
  name: string;
  status?: 'uploading' | 'done' | 'error' | 'removed';
  url?: string;
  thumbUrl?: string;
  response?: any;
}
fieldProps.name
string
default:"'file'"
Field name for file parameter in upload request.
fieldProps.headers
Record<string, string>
HTTP headers for upload request:
headers={{
  Authorization: `Bearer ${token}`,
  'X-Custom-Header': 'value'
}}
fieldProps.data
object | ((file: UploadFile) => object)
Additional data sent with upload request:
data={{ userId: '123', type: 'document' }}
// or
data={(file) => ({ fileName: file.name })}
fieldProps.withCredentials
boolean
default:"false"
Whether to send cookies with upload request.
fieldProps.multiple
boolean
default:"false"
Whether to allow selecting multiple files at once.
fieldProps.maxCount
number
Maximum number of files in the list. When limit is reached, new uploads replace old files.
fieldProps.directory
boolean
default:"false"
Whether to support uploading entire directories.
fieldProps.beforeUpload
(file: File, fileList: File[]) => boolean | Promise<File> | Upload.LIST_IGNORE
Hook before uploading. Return false or reject Promise to prevent upload:
beforeUpload={(file) => {
  const isLt2M = file.size / 1024 / 1024 < 2;
  if (!isLt2M) {
    message.error('File must be smaller than 2MB!');
  }
  return isLt2M || Upload.LIST_IGNORE;
}}
fieldProps.customRequest
(options: UploadRequestOption) => void
Custom upload implementation. Override default upload behavior:
interface UploadRequestOption {
  file: File;
  onProgress?: (event: { percent: number }) => void;
  onSuccess?: (body: any, xhr?: XMLHttpRequest) => void;
  onError?: (error: Error) => void;
}
fieldProps.onChange
(info: { file: UploadFile, fileList: UploadFile[] }) => void
Callback when upload state changes. Triggered on start, progress, success, and error.
fieldProps.onRemove
(file: UploadFile) => boolean | Promise<boolean>
Callback before removing file. Return false to prevent removal.
fieldProps.onPreview
(file: UploadFile) => void
Callback when file preview is clicked. Default behavior shows image preview.
fieldProps.onDownload
(file: UploadFile) => void
Callback when download button is clicked.
fieldProps.itemRender
(originNode: ReactNode, file: UploadFile, fileList: UploadFile[], actions: { download: Function, preview: Function, remove: Function }) => ReactNode
Custom render function for each file item in the list.
fieldProps.showUploadList
boolean | ShowUploadListInterface
Whether to show upload list. Can be boolean or detailed configuration:
showUploadList={{
  showPreviewIcon: true,
  showRemoveIcon: true,
  showDownloadIcon: false,
  removeIcon: <DeleteOutlined />,
  downloadIcon: <DownloadOutlined />
}}

ProFormUploadDragger

Drag-and-drop upload component with drop zone.

Import

import { ProFormUploadDragger } from '@ant-design/pro-components';

Usage

<ProFormUploadDragger
  name="files"
  label="Files"
  title="Click or drag files to this area to upload"
  description="Support single or bulk upload"
  action="/api/upload"
/>

Props

Extends ProFormUploadButton props and Ant Design Upload.Dragger props.
title
ReactNode
default:"'Click or drag file to this area to upload'"
Main text displayed in the upload area.
icon
ReactNode
default:"<InboxOutlined />"
Large icon displayed at the top of the upload area.
description
ReactNode
default:"'Support single or bulk upload'"
Description text displayed below the title.
children
ReactNode
Additional content displayed at the bottom of the upload area. Can include help text or links.
max
number
Maximum number of files allowed. When limit is reached, dragger area is hidden.
action
string
Upload endpoint URL.
accept
string
Accepted file types.
value
UploadFile[]
Controlled file list value.
onChange
(info: { file: UploadFile, fileList: UploadFile[] }) => void
Callback when upload state changes.
fieldProps
DraggerProps
All props from Upload.Dragger are supported through fieldProps. Refer to ProFormUploadButton props for detailed fieldProps options.

Common Features

Build docs developers (and LLMs) love