@cruisecritic/react-dropzone-uploader

中文文档
2.12.6发布于 2022/06/14MITTypeScriptCommonJS近 30 天下载 2933

React file dropzone and uploader: fully customizable, progress indicators, upload cancellation and restart, zero deps and excellent TypeScript support

原始使用文档
文档目录12 节
  1. Features
  2. Documentation
  3. Installation
  4. Quick Start
  5. Examples
  6. Props
  7. Browser Support
  8. UMD Build
  9. Contributing
  10. Shout Outs
  11. Running Dev
  12. Thanks

React Dropzone Uploader

NPM npm bundle size (minified + gzip)

React Dropzone Uploader is a customizable file dropzone and uploader for React.

Note: This has been forked from fortana-co/react-dropzone-uploader and modified to export .d.ts files instead of copying over the .tsx files for typescript support.

Features

  • Detailed file metadata and previews, especially for image, video and audio files
  • Upload status and progress, upload cancellation and restart
  • Easily set auth headers and additional upload fields (see S3 examples)
  • Customize styles using CSS or JS
  • Take full control of rendering with component injection props
  • Take control of upload lifecycle
  • Modular design; use as standalone dropzone, file input, or file uploader
  • Cross-browser support, mobile friendly, including direct uploads from camera
  • Lightweight and fast
  • Excellent TypeScript definitions

Documentation

https://react-dropzone-uploader.js.org

Installation

npm install --save react-dropzone-uploader

Import default styles in your app.

import 'react-dropzone-uploader/dist/styles.css'

Quick Start

RDU handles common use cases with almost no config. The following code gives you a dropzone and clickable file input that accepts image, audio and video files. It uploads files to https://httpbin.org/post, and renders a button to submit files that are done uploading. Check out a live demo.

import 'react-dropzone-uploader/dist/styles.css'
import Dropzone from 'react-dropzone-uploader'

const MyUploader = () => {
  // specify upload params and url for your files
  const getUploadParams = ({ meta }) => { return { url: 'https://httpbin.org/post' } }
  
  // called every time a file's `status` changes
  const handleChangeStatus = ({ meta, file }, status) => { console.log(status, meta, file) }
  
  // receives array of files that are done uploading when submit button is clicked
  const handleSubmit = (files) => { console.log(files.map(f => f.meta)) }

  return (
    <Dropzone
      getUploadParams={getUploadParams}
      onChangeStatus={handleChangeStatus}
      onSubmit={handleSubmit}
      accept="image/*,audio/*,video/*"
    />
  )
}

Examples

See more live examples here: https://react-dropzone-uploader.js.org/docs/examples.

Props

Check out the full table of RDU's props.

Browser Support

ChromeFirefoxEdgeSafariIEiOS SafariChrome for Android
✔✔✔10+, 9*11*✔✔

* requires Promise polyfill, e.g. @babel/polyfill

UMD Build

This library is available as an ES Module at https://unpkg.com/react-dropzone-uploader@VERSION/dist/react-dropzone-uploader.umd.js.

If you want to include it in your page, you need to include the dependencies and CSS as well.

<script src="https://cdnjs.cloudflare.com/ajax/libs/react/16.4.2/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/16.4.2/umd/react-dom.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/prop-types/15.6.2/prop-types.min.js"></script>

<script src="https://unpkg.com/react-dropzone-uploader@VERSION/dist/react-dropzone-uploader.umd.js"></script>
<link rel"stylesheet" href="https://unpkg.com/react-dropzone-uploader@VERSION/dist/styles.css"></script>

Contributing

There are a number of places RDU could be improved; see here.

For example, RDU has solid core functionality, but has a minimalist look and feel. It would be more beginner-friendly with a larger variety of built-in components.

Shout Outs

Thanks to @nchen63 for helping with TypeScript defs!

Running Dev

Clone the project, install dependencies, and run the dev server.

git clone git://github.com/fortana-co/react-dropzone-uploader.git
cd react-dropzone-uploader
yarn
npm run dev

This runs code in examples/src/index.js, which has many examples that use Dropzone. The library source code is in the /src directory.

Thanks

Thanks to react-dropzone, react-select, and redux-form for inspiration.

版本与发布记录

@cruisecritic/react-dropzone-uploader 共发布 6 个版本,首次发布于 2022/06/11;过去 12 个月发布了 0 个版本。

版本发布日期距今
2.12.6latest2022/06/144 年前
2.12.52022/06/114 年前
2.12.42022/06/114 年前
2.12.22022/06/114 年前
2.12.12022/06/114 年前
2.12.02022/06/114 年前

关于 @cruisecritic/react-dropzone-uploader 的常见问题

@cruisecritic/react-dropzone-uploader 是什么?

React file dropzone and uploader: fully customizable, progress indicators, upload cancellation and restart, zero deps and excellent TypeScript support

如何安装 @cruisecritic/react-dropzone-uploader?

在项目目录运行 npm install @cruisecritic/react-dropzone-uploader,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:prop-types(>=15.5.10)、react(>=16.2.0)、react-dom(>=16.2.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@cruisecritic/react-dropzone-uploader 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cruisecritic/react-dropzone-uploader 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cruisecritic/react-dropzone-uploader 可以商用吗?

@cruisecritic/react-dropzone-uploader 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cruisecritic/react-dropzone-uploader 的下载量有多少?

根据 npm 官方下载统计,@cruisecritic/react-dropzone-uploader 在 2026/10/11 – 2026/11/09 这 30 天内被下载 2,933 次,日均约 98 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cruisecritic/react-dropzone-uploader 还在维护吗?

最新版本 2.12.6 发布于 2022/06/14(4 年前);至今共发布 6 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/06/11。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。