Registry / web-framework / rc-upload

rc-upload

JSON →
library4.11.0jsnpmunverified

rc-upload is a lightweight, unstyled React UI component for handling file uploads. It provides foundational upload capabilities such as drag-and-drop, folder uploads, and paste-from-clipboard functionality without imposing any specific visual design, allowing developers full control over the user interface. The current stable version is 4.11.0. The project maintains an active release cadence, with minor versions released periodically to introduce new features, address bugs, and update dependencies. Its key differentiators include its headless architecture, extensive customization options via props like `customRequest` and `beforeUpload`, and support for modern browser-based upload features. It is a core utility often used as a building block for more complex upload components.

npm install rc-upload
INSTALL
IMPORT
SIG · RC-UPLOAD
R
rc-upload
web-frameworkjavascriptv4.11.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Upload
import Upload from 'rc-upload';
import { Upload } from 'rc-upload';
The primary `Upload` component is exported as a default. Attempting to import it as a named export will fail.
UploadProps
import type { UploadProps } from 'rc-upload';
import { UploadProps } from 'rc-upload';
Importing types directly as values might lead to bundling issues or unnecessary code. Use `import type` for explicit type imports.
RcFile
import type { RcFile } from 'rc-upload';
This type extends the standard `File` interface and is used internally and in callback functions like `beforeUpload` or `onStart`.

Demonstrates a basic file upload component with a mock server action and callback handlers for `onStart`, `onSuccess`, `onError`, `onProgress`, and `beforeUpload` to manage file state and validation.

import React, { useState } from 'react'; import Upload from 'rc-upload'; import type { UploadProps, RcFile } from 'rc-upload'; const App: React.FC = () => { const [fileList, setFileList] = useState<RcFile[]>([]); const handleStart: UploadProps['onStart'] = (file) => { console.log('onStart', file.name); setFileList((prev) => [...prev, { ...file, status: 'uploading' }]); }; const handleSuccess: UploadProps['onSuccess'] = (response, file) => { console.log('onSuccess', response, file.name); setFileList((prev) => prev.map(f => f.uid === file.uid ? { ...f, status: 'done' } : f)); }; const handleError: UploadProps['onError'] = (err, response, file) => { console.error('onError', err, response, file.name); setFileList((prev) => prev.map(f => f.uid === file.uid ? { ...f, status: 'error' } : f)); }; const handleProgress: UploadProps['onProgress'] = (event, file) => { console.log('onProgress', Math.round(event.percent || 0) + '%', file.name); }; const beforeUpload: UploadProps['beforeUpload'] = (file, currentFileList) => { const isLt2M = file.size / 1024 / 1024 < 2; if (!isLt2M) { alert('File must be smaller than 2MB!'); return false; // Stop upload } console.log('beforeUpload', file.name, currentFileList.length); return true; // Proceed with upload }; return ( <div> <h1>File Upload Demo</h1> <Upload action="https://www.mocky.io/v2/5cc8019d300000980a055e76" // Mock API endpoint method="POST" name="myFile" multiple={true} onStart={handleStart} onSuccess={handleSuccess} onError={handleError} onProgress={handleProgress} beforeUpload={beforeUpload} withCredentials={false} // Adjust as needed for your backend style={{ padding: '20px', border: '2px dashed #ccc', textAlign: 'center', cursor: 'pointer', margin: '20px 0' }} > <button type="button">Click to Upload or Drag File Here</button> </Upload> {fileList.length > 0 && ( <div> <h2>Upload Status:</h2> <ul> {fileList.map((file) => ( <li key={file.uid}> {file.name} - {file.status} {file.status === 'uploading' && '(in progress)'} </li> ))} </ul> </div> )} </div> ); }; export default App;
Debug
Known issues
breakingThe `directory` prop was deprecated in `v4.10.0` in favor of the `folder` prop for uploading entire directories. While `directory` might still function, it is not recommended and could be removed in future major versions.
fix
Replace `directory={true}` with `folder={true}` when enabling directory uploads.
affects: >=4.10.0
gotcha`rc-upload` is a headless component and does not provide any default UI or styling. Developers must implement their own visual presentation and interaction around the `Upload` component.
fix
Wrap the `Upload` component with custom UI elements (e.g., a button, a drag-and-drop area) and apply your own CSS for styling.
affects: >=1.0.0
gotchaWhile the README historically showed CommonJS `require('rc-upload')` for usage, modern React applications primarily use ES module `import` syntax. Using `require` in an ESM-only environment or attempting named imports when only a default export exists will lead to errors.
fix
In modern projects, always use `import Upload from 'rc-upload';`.
affects: >=1.0.0
breakingThe type annotations for the `beforeUpload` function were updated in `v4.11.0`. While this is primarily a TypeScript-related change and not a functional one, projects with strict TypeScript configurations or custom `beforeUpload` implementations might encounter type errors after upgrading.
fix
Review and adjust the type signatures of custom `beforeUpload` functions to align with the updated typings, ensuring correct handling of the `file` and `fileList` arguments.
affects: >=4.11.0
gotcha`rc-upload` is distinct from `@rc-component/upload`. Although the GitHub repository `react-component/upload` shows commits related to both, `@rc-component/upload` is a separate package (currently at v1.x) and not a direct replacement or rename of `rc-upload` (v4.x). Ensure you are installing and importing from the correct package, `rc-upload`.
fix
Verify the package name in your `package.json` and `import` statements. If you intend to use `rc-upload`, ensure your dependencies list `rc-upload` and your imports are `from 'rc-upload'`.
affects: >=4.0.0
Errors
Common errors & fixes
Error: 'Upload' is not exported from 'rc-upload'
Attempting to import `Upload` as a named export when it is exported as a default export.
fix
Change the import statement to `import Upload from 'rc-upload';`
Type 'boolean' is not assignable to type 'string | ((file: File) => string | Promise<string>)'
Providing an incorrect type for the `action` prop, which expects a URL string or a function that returns a URL.
fix
Ensure the `action` prop is either a `string` (e.g., `action="/upload-target"`) or a function returning a `string` or `Promise<string>` (e.g., `action={(file) => `/api/upload/${file.name}`}`).
Property 'directory' does not exist on type 'UploadProps'. Did you mean 'folder'?
Using the deprecated `directory` prop (removed since v4.10.0) instead of the `folder` prop.
fix
Replace `directory={true}` with `folder={true}` to enable folder uploads.
Upgrade
Version history
4.11.0latest on npm
Audit
Dependencies
reactrequiredPeer dependency for React component rendering.
react-domrequiredPeer dependency for React component rendering.
Agent activity
7 hits · last 30 days
node
6
OpenAI (training)
1
Resources
rc-upload — npm install rc-upload · libregistry