logoNamu Design

⌘ K
  • Design
  • Development
  • Components
  • Blog
  • Resources
1.0.0
  • Components Overview
  • General
    • Button
    • FloatButtonNew
    • Icon
    • Typography
  • Layout
    • Divider
    • Grid
    • Layout
    • Space
  • Navigation
    • Anchor
    • Breadcrumb
    • Dropdown
    • Menu
    • Pagination
    • Steps
  • Data Entry
    • AutoComplete
    • Cascader
    • Checkbox
    • ColorPickerNew
    • DatePicker
    • Form
    • Input
    • InputNumber
    • Mentions
    • Radio
    • Rate
    • Select
    • Slider
    • Switch
    • TimePicker
    • Transfer
    • TreeSelect
    • Upload
  • Data Display
    • Avatar
    • Badge
    • Calendar
    • Card
    • Carousel
    • Collapse
    • Descriptions
    • Empty
    • Image
    • List
    • Popover
    • QRCodeNew
    • Segmented
    • Statistic
    • Table
    • Tabs
    • Tag
    • Timeline
    • Tooltip
    • TourNew
    • Tree
  • Feedback
    • Alert
    • Drawer
    • Message
    • Modal
    • Notification
    • Popconfirm
    • Progress
    • Result
    • Skeleton
    • Spin
    • Watermark
  • Other
    • Affix
    • AppNew
    • ConfigProvider
When To Use
Examples
Upload by clicking
Avatar
Default Files
Pictures Wall
Pictures with picture-circle type
Complete control over file list
Drag and Drop
Upload directory
Upload manually
Upload png file only
Pictures with list style
Customize preview file
Max Count
Transform file before request
Aliyun OSS
custom action icon
Drag sorting of uploadList
Crop image before uploading
Customize Progress Bar
API
UploadFile
onChange
Design Token
FAQ
How do I implement upload server side?
I want to display download links.
How to use customRequest?
Why will the fileList that's in control not trigger onChange status update when the file is not in the list?
Why does onChange sometimes return File object and other times return { originFileObj: File }?
Why sometimes Chrome can not upload?

Upload

  • TreeSelectAvatar

    Resources

    Namu Design Charts
    Namu Design Pro
    Namu Design Pro Components
    Namu Design Mobile
    Namu Design Mini
    Namu Design Landing-Landing Templates
    Scaffolds-Scaffold Market
    Umi-React Application Framework
    dumi-Component doc generator
    qiankun-Micro-Frontends Framework
    ahooks-React Hooks Library
    Ant Motion-Motion Solution
    China Mirror 🇨🇳

    Community

    Awesome Namu Design
    Medium
    Twitter
    yuqueNamu Design in YuQue
    Namu Design in Zhihu
    Experience Cloud Blog
    seeconfSEE Conf-Experience Tech Conference

    Help

    GitHub
    Change Log
    FAQ
    Bug Report
    Issues
    Discussions
    StackOverflow
    SegmentFault

    Ant XTechMore Products

    yuqueYuQue-Document Collaboration Platform
    AntVAntV-Data Visualization
    EggEgg-Enterprise Node.js Framework
    kitchenKitchen-Sketch Toolkit
    xtechAnt Financial Experience Tech
    Theme Editor
    Made with ❤ by
    Ant Group and Namu Design Community

    Upload the file by selecting or dragging.

    When To Use

    Uploading is the process of publishing information (web pages, text, pictures, video, etc.) to a remote server via a web page or upload tool.

    • When you need to upload one or more files.
    • When you need to show the process of uploading.
    • When you need to upload files by dragging and dropping.

    Examples

    Upload by clicking

    Classic mode. File selection dialog pops up when upload button is clicked.

    expand codeexpand code
    Default Files

    Use defaultFileList for uploaded files when page init.

    expand codeexpand code
    Pictures with picture-circle type

    Alternative display for picture-card.

    expand codeexpand code
    Drag and Drop

    You can drag files to a specific area, to upload. Alternatively, you can also upload by selecting.

    We can upload several files at once in modern browsers by giving the input the multiple attribute.

    expand codeexpand code
    Upload manually

    Upload files manually after beforeUpload returns false.

    expand codeexpand code
    Pictures with list style

    If uploaded file is a picture, the thumbnail can be shown. IE8/9 do not support local thumbnail show. Please use thumbUrl instead.

    expand codeexpand code
    Max Count

    Limit files with maxCount. Will replace current one when maxCount is 1.

    expand codeexpand code
    Aliyun OSS

    Use Aliyun OSS upload example.

    expand codeexpand code
    Drag sorting of uploadList

    By using itemRender, we can integrate upload with dnd-kit to implement drag sorting of uploadList.

    expand codeexpand code
    Customize Progress Bar

    Use progress for customize progress bar.

    expand codeexpand code
    Avatar

    Click to upload user's avatar, and validate size and format of picture with beforeUpload.

    The return value of function beforeUpload can be a Promise to check asynchronously. demo

    expand codeexpand code
    Pictures Wall

    After users upload picture, the thumbnail will be shown in list. The upload button will disappear when count meets limitation.

    expand codeexpand code
    Complete control over file list

    You can gain full control over filelist by configuring fileList. You can accomplish all kinds of customized functions. The following shows two circumstances:

    1. limit the number of uploaded files.

    2. read from response and show file link.

    expand codeexpand code
    Upload directory

    You can select and upload a whole directory.

    expand codeexpand code
    Upload png file only

    beforeUpload only prevent upload behavior when return false or reject promise, the prevented file would still show in file list. Here is the example you can keep prevented files out of list by return UPLOAD.LIST_IGNORE.

    expand codeexpand code
    Customize preview file

    Customize local preview. Can handle with non-image format files such as video.

    expand codeexpand code
    Transform file before request

    Use beforeUpload for transform file before request such as add a watermark.

    expand codeexpand code
    custom action icon

    Use showUploadList for custom action icons of files.

    expand codeexpand code
    Crop image before uploading

    Use antd-img-crop to crop image before uploading.

    expand codeexpand code

    API

    Common props ref:Common props

    PropertyDescriptionTypeDefaultVersion
    acceptFile types that can be accepted. See input accept Attributestring-
    actionUploading URLstring | (file) => Promise<string>-
    beforeUploadHook function which will be executed before uploading. Uploading will be stopped with false or a rejected Promise returned. When returned value is Upload.LIST_IGNORE, the list of files that have been uploaded will ignore it. Warning:this function is not supported in IE9(file, fileList) => boolean | Promise<File> | Upload.LIST_IGNORE-
    customRequestOverride for the default xhr behavior allowing for additional customization and the ability to implement your own XMLHttpRequestfunction-
    dataUploading extra params or function which can return uploading extra paramsobject | (file) => object | Promise<object>-
    defaultFileListDefault list of files that have been uploadedobject[]-
    directorySupport upload whole directory (caniuse)booleanfalse
    disabledDisable upload buttonbooleanfalse
    fileListList of files that have been uploaded (controlled). Here is a common issue #2423 when using itUploadFile[]-
    headersSet request headers, valid above IE10object-
    iconRenderCustom show icon(file: UploadFile, listType?: UploadListType) => ReactNode-
    isImageUrlCustomize if render <img /> in thumbnail(file: UploadFile) => boolean(inside implementation)
    itemRenderCustom item of uploadList(originNode: ReactElement, file: UploadFile, fileList: object[], actions: { download: function, preview: function, remove: function }) => React.ReactNode-4.16.0
    listTypeBuilt-in stylesheets, support for four types: text, picture, picture-card or picture-circlestringtextpicture-circle(5.2.0+)
    maxCountLimit the number of uploaded files. Will replace current one when maxCount is 1number-4.10.0
    methodThe http method of upload requeststringpost
    multipleWhether to support selected multiple files. IE10+ supported. You can select multiple files with CTRL holding down while multiple is set to be truebooleanfalse
    nameThe name of uploading filestringfile
    openFileDialogOnClickClick open file dialogbooleantrue
    previewFileCustomize preview file logic(file: File | Blob) => Promise<dataURL: string>-
    progressCustom progress barProgressProps (support type="line" only){ strokeWidth: 2, showInfo: false }4.3.0
    showUploadListWhether to show default upload list, could be an object to specify showPreviewIcon, showRemoveIcon, showDownloadIcon, removeIcon and downloadIcon individuallyboolean | { showPreviewIcon?: boolean, showDownloadIcon?: boolean, showRemoveIcon?: boolean, previewIcon?: ReactNode | (file: UploadFile) => ReactNode, removeIcon?: ReactNode | (file: UploadFile) => ReactNode, downloadIcon?: ReactNode | (file: UploadFile) => ReactNode }truefunction: 4.7.0
    withCredentialsThe ajax upload with cookie sentbooleanfalse
    onChangeA callback function, can be executed when uploading state is changing, see onChangefunction-
    onDropA callback function executed when files are dragged and dropped into the upload area(event: React.DragEvent) => void-4.16.0
    onDownloadClick the method to download the file, pass the method to perform the method logic, and do not pass the default jump to the new TABfunction(file): void(Jump to new TAB)
    onPreviewA callback function, will be executed when the file link or preview icon is clickedfunction(file)-
    onRemoveA callback function, will be executed when removing file button is clicked, remove event will be prevented when the return value is false or a Promise which resolve(false) or rejectfunction(file): boolean | Promise-

    UploadFile

    Extends File with additional props.

    PropertyDescriptionTypeDefaultVersion
    crossOriginCORS settings attributes'anonymous' | 'use-credentials' | ''-4.20.0
    nameFile namestring--
    percentUpload progress percentnumber--
    statusUpload status. Show different style when configurederror | success | done | uploading | removed--
    thumbUrlThumb image urlstring--
    uidunique id. Will auto-generate when not providedstring--
    urlDownload urlstring--

    onChange

    The function will be called when uploading is in progress, completed, or failed.

    When uploading state change, it returns:

    {
    file: { /* ... */ },
    fileList: [ /* ... */ ],
    event: { /* ... */ },
    }
    1. file File object for the current operation.

      {
      uid: 'uid', // unique identifier, negative is recommended, to prevent interference with internally generated id
      name: 'xx.png', // file name
      status: 'done' | 'uploading' | 'error' | 'removed', // Intercepted file by beforeUpload doesn't have a status field.
      response: '{"status": "success"}', // response from server
      linkProps: '{"download": "image"}', // additional HTML props of file link
      xhr: 'XMLHttpRequest{ ... }', // XMLHttpRequest Header
      }
    2. fileList current list of files

    3. event response from the server, including uploading progress, supported by advanced browsers.

    Design Token

    Component Token

    Global Token

    FAQ

    How do I implement upload server side?

    • You can consult jQuery-File-Upload about how to implement server side upload interface.
    • There is a mock example of express in rc-upload.

    I want to display download links.

    Please set property url of each item in fileList to control the content of the link.

    How to use customRequest?

    See https://github.com/react-component/upload#customrequest.

    Why will the fileList that's in control not trigger onChange status update when the file is not in the list?

    onChange will only trigger when the file is in the list, it will ignore any events removed from the list. Please note that there does exist a bug which makes an event still trigger even when the file is not in the list before 4.13.0.

    Why does onChange sometimes return File object and other times return { originFileObj: File }?

    For compatible case, we return File object when beforeUpload return false. It will merge to { originFileObj: File } in the next major version. Current version is compatible to get origin file by info.file.originFileObj. You can change this before a major release.

    Why sometimes Chrome can not upload?

    Chrome update will also break native upload. Please restart Chrome to finish the upload work.

    Ref:

    • #32672
    • #32913
    • #33988
    xxx.png
    yyy.png
    zzz.png
    image.pngimage.png
    Uploading...
    image.png
    image.png
    Upload

    Click or drag file to this area to upload

    Support for a single or bulk upload. Strictly prohibited from uploading company data or other banned files.

    xxx.png
    yyy.pngyyy.png
    zzz.png


    xxx.png
    yyy.pngyyy.png
    zzz.png
    image1.png
    image2.png
    image3.png
    image4.png
    image.png
    Upload
    Upload
    image.pngimage.png
    image.pngimage.png
    image.pngimage.png
    image.pngimage.png
    Uploading...
    image.png
    image.png
    Upload
    xxx.png
    xxx.png
    yyy.png
    zzz.png
    image.pngimage.png
    + Upload