Skip to content

Repository files navigation

@rc-component/upload

Ant Design Part of the Ant Design ecosystem.

📤 Low-level React upload primitive for Ajax, drag, paste, directory, and custom requests.

NPM versionnpm downloadsbuild statusCodecovbundle sizedumi

English | 简体中文

Highlights

  • Supports Ajax uploads with progress, headers, credentials, and custom request overrides.
  • Supports directory, drag, paste, async action, and before-upload flows.
  • Exposes abort(file) through the component instance for active requests.
  • Provides semantic classNames and styles slots for the hidden input.

Install

npm install @rc-component/upload

Usage

importUploadfrom'@rc-component/upload';exportdefault()=>(<Uploadaction="/upload"onStart={file=>{console.log('start',file.name);}}onSuccess={(response,file)=>{console.log('success',file.name,response);}}><buttontype="button">Upload</button></Upload>);

Online preview: https://upload.react-component.vercel.app/

Examples

Run the local dumi site:

npm install
npm start

Then open http://localhost:8000.

API

Upload

NameTypeDefaultDescription
acceptstring | AcceptConfig-Input accept config.
actionstring | (file) => string | PromiseLike<string>-Upload URL or async resolver.
beforeUpload(file, fileList) => BeforeUploadFileType | Promise<void | BeforeUploadFileType> | void-Validate or transform before upload. Return false to stop upload.
classNamestring-Root class name.
classNames{ input?: string }-Semantic class names.
componentReact.ComponentType | string'span'Root component.
customRequestCustomUploadRequestOption-Override default request behavior.
dataobject | (file) => object{}Extra upload data.
directorybooleanfalseEnable directory upload.
disabledbooleanfalseDisable upload trigger.
hasControlInsidebooleanfalseWhether child already contains a control element.
headersRecord<string, string>{}Request headers.
idstring-Input id.
method'POST' | 'PUT' | 'PATCH' | 'post' | 'put' | 'patch''post'Request method.
multiplebooleanfalseAllow multiple file selection.
namestring'file'File field name.
onBatchStart(fileList) => void-Called when a batch starts.
onError(error, response, file) => void-Upload error callback.
onProgress(event, file) => void-Upload progress callback.
onStart(file) => void-Upload start callback.
onSuccess(response, file, xhr) => void-Upload success callback.
openFileDialogOnClickbooleantrueOpen file dialog when root is clicked.
pastablebooleanfalseEnable paste upload.
prefixClsstring'rc-upload'Prefix class name.
styleReact.CSSProperties-Root style.
styles{ input?: React.CSSProperties }-Semantic styles.
withCredentialsbooleanfalseSend credentials with Ajax upload.

Methods

NameTypeDescription
abort(file: RcFile) => voidAbort an active upload.

Development

npm install
npm start
npm test
npm run tsc
npm run compile
npm run build

The dumi site runs at http://localhost:8000 by default.

Release

npm run prepublishOnly

The release flow is handled by @rc-component/np through the rc-np command after the package build.

License

@rc-component/upload is released under the MIT license.

About

📤 Low-level React upload primitive for Ajax, drag, paste, directory, and custom requests.

Topics

Resources

Stars

803 stars

Watchers

31 watching

Forks

Releases

Sponsor this project

Packages

Used by

Contributors

Languages