- Notifications
You must be signed in to change notification settings - Fork40
Modern file uploading - components & hooks for React
License
rpldy/react-uploady
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Modern file-upload components & hooks for React.
Contents
React-Uploady is a lightweight library - enabling you to build (client-side) file-upload features with just a few lines of code. Uploady provides the foundations needed to upload files from the browser - The rest is up to you.
The philosophy behind this library is that it should be as simple as possible to use, yet customizable at every point.You can start simple, or you can configure just about every aspect of the upload flow.For this purpose, there are components, hooks, and plenty of features.You get to choose which ones you need and only install the dependencies required (SeePackages details below)
React-Uploady has a small footprint (by design) with very few (tiny) dependencies.
Bundle | Minified size | GZipped size |
---|---|---|
core | 29.1KB | 10.5KB |
core + ui | 36.9KB | 13.3KB |
core + ui + chunked support | 44.1KB | 15.7KB |
everything | 71.0KB | 22.9KB |
The best place to get started is at our:React-Uploady Documentation Website
Another great place to learn about React-Uploady is ourvideo series on Youtube.
For a list of versions and changes, see theCHANGELOG
Please check thediscussions area here in Github. If you have a question about use-cases or flows you'd like to achieve with Uploady, discussions is the place to look for existing answers or add your own.
If you're using Uploady in Production, please drop a commenthere. It's always great to hear how people and companies use it.
React-uploady is a mono-repo, and as such provides multiple packages with different functionality.
For React applications, at the very least, you will need the Uploady provider:
#Yarn: $ yarn add @rpldy/uploady#NPM: $ npm i @rpldy/uploady
If you wish to use the uploading mechanism (no UI), at the very least, you will need the Uploader:
#Yarn: $ yarn add @rpldy/uploader#NPM: $ npm i @rpldy/uploader
After that, you can add additional packages as needed. See below for more details.
- @rpldy/uploader - The processing and queuing engine
- @rpldy/uploady - The context provider for react-uploady and hooks (lots of hooks)
- @rpldy/upload-button - Upload button component and asUploadButton HOC
- @rpldy/upload-preview - Image&video preview component for files being uploaded
- @rpldy/upload-url-input - Input component to send URL as upload info (ex:Cloudinary)
- @rpldy/upload-drop-zone - (Drag&)Drop zone to upload files and folder content
- @rpldy/upload-paste - Easily add paste-to-upload to React components
- @rpldy/retry-hooks - Hooks to interact with the retry mechanism
- @rpldy/chunked-uploady - Wrapper for Uploady with support for chunked uploads
- @rpldy/tus-uploady - Wrapper for Uploady with support for tus(resumable) uploads
- @rpldy/native-uploady - Uploady for React Native (no react-dom)
- @rpldy/sender - Uploady's main file sender (XHR)
- @rpldy/chunked-sender - add chunked uploads support on top of the XHR Sender
- @rpldy/tus-sender - add TUS resumable upload support
- @rpldy/mock-sender - use Mock sender for testing purposes
- @rpldy/retry - Add support for retrying failed uploads
- @rpldy/shared - Internal set of utils+types that all packages require
- @rpldy/shared-ui - Internal set of utils+types that all UI packages require
- @rpldy/life-events - providescancellable pub/sub "events"
- @rpldy/safe-storage - safe (don't throw) versions of local and session storage
- @rpldy/simple-state - deep proxy object, so it's only updateable through an update method
For specific usage, see documentation in the relevant package README file.
For upload options, see the@rpldy/uploady docs.
This example shows how you add Uploady and UploadButton to your app.This is all it takes to get file uploading to work in your React application.
importReactfrom"react";importUploadyfrom"@rpldy/uploady";importUploadButtonfrom"@rpldy/upload-button";constApp=()=>(<Uploadydestination={{url:"https://my-server/upload"}}><UploadButton/></Uploady>);
In case you want to use your own component as the upload trigger, use the asUploadButton HOC:
importReactfrom"react";importUploadyfrom"@rpldy/uploady";import{asUploadButton}from"@rpldy/upload-button";constDivUploadButton=asUploadButton((props)=>{return<div{...props}style={{cursor:"pointer"}}> DIV Upload Button</div>});constApp=()=>(<Uploadydestination={{url:"https://my-server/upload"}}><DivUploadButton/></Uploady>);
importReactfrom"react";importUploady,{useItemProgressListener}from"@rpldy/uploady";importUploadButtonfrom"@rpldy/upload-button";//must be rendered inside <Uploady>constLogProgress=()=>{useItemProgressListener((item)=>{console.log(`>>>>> (hook) File${item.file.name} completed:${item.completed}`);});returnnull;}constApp=()=>(<Uploadydestination={{url:"https://my-server/upload"}}><LogProgress/><UploadButton/></Uploady>);
importReactfrom"react";importTusUploadyfrom"@rpldy/tus-uploady";importUploadButtonfrom"@rpldy/upload-button";constApp=()=>(<TusUploadydestination={{url:"https://my-tus-server/upload"}}chunkSize={2142880}sendDataOnCreate><UploadButton/></TusUploady>);
Can be used with servers that support chunked uploads
importReactfrom"react";importChunkedUploadyfrom"@rpldy/chunked-uploady";importUploadButtonfrom"@rpldy/upload-button";constApp=()=>(<ChunkedUploadydestination={{url:"https://my-server/upload"}}chunkSize={5242880}><UploadButton/></ChunkedUploady>);
These are the options that are passed to theuploader to configure aspects of the upload process.For example, whether files can be grouped in a single request (by default, no).
Upload Options are typically passed to theUploady instance. But these can be overridden. For example, by props passed to theupload button.Or even duringupload processing.
Passed as a part of the upload options. It's an object that is used to configure the end-point where the files will be uploaded to.Its type is definedhere.
See more information in theUploady doc.
At the very least, a destination should contain a URL property with the server endpoint.
(uploader:UploaderType,trigger:Trigger<mixed>)=>UploaderType
Enhancers are functions that can enhance an uploader instance. They are also passed as part of the options given to the Uploady instance.
As they are applied when the uploader instance is created, they can change the way uploader does things or pass different defaults.
See thisguide for practical information and sample code.
When a file or files are handed over to the uploader, they are grouped into a batch.This batch will have its own lifetimeevents.With a batch ID, it is possible to cancel all files that are part of it. It can also be used to retry all files in the batch (see@rpldy/retry).
Each file (or URL) added to the uploader is wrapped by a BatchItem object. They will have a unique ID within the life-time of the uploader instance.A BatchItem has its own lifetimeevents.
Uploady supports resumable uploads through thetusprotocol.Instead of using <Uploady> from @rpldy/uploady, use <TusUploady> from @rpldy/tus-uploady and you will have resumable upload support on the client side.Your server will also have to support the same protocol for this to work, of course.
See the@rpldy/tus-uploady documentation for more details.
React-uploady is also available on CDNs such asunpkg.com andjsdelivr.com
See thisguide for more information on how to use.
You will most likely need the polyfill (core js) bundle as well (load it first):
- core bundles ->https://cdn.jsdelivr.net/npm/@rpldy/uploady/lib/umd/polyfills-bundle.js
- everything bundle ->https://cdn.jsdelivr.net/npm/@rpldy/uploady/lib/umd/polyfills-all-bundle.js
You will most likely need the polyfill (core js) bundle as well (load it first):
- core bundles ->https://unpkg.com/@rpldy/uploady/lib/umd/polyfills-bundle.js
- everything bundle ->https://unpkg.com/@rpldy/uploady/lib/umd/polyfills-all-bundle.js
Note that unpkg does a redirect to the latest version in case the URL doesn't already contain it. So don't copy any of the URLs above into your code.Instead, load them in the browser first and then copy the final URL from there (after the redirect).
Show Uploady your support by giving us a⭐.
If you'd like to help Uploady grow & improve, take a look at theContributing doc.
TheDiscussions page is a great place to ask questions, raise ideas and interact with Uploady maintainer, users and contributors.
Already using Uploady in Production? Let us know how & where in this opendiscussion.
Companies/Organizations that have contributed to the project:
Want to help sustain and grow Uploady? You can become a financial backer on OpenCollective.
Become a financial contributor and help us sustain our community.
You can make a one-time contribution or on a monthly basis
Or justbuy me a coffee 😄
logo's wing thanks toIllustration Vectors by Vecteezy
About
Modern file uploading - components & hooks for React