Uploady Documentation
website·Indexed 29 days ago
https://react-uploady.netlify.app/A React file upload library featuring a modular architecture with support for chunked uploads, TUS, and Cloudinary. Includes a comprehensive API for hooks, enhancers, and senders such as XHRSender and MockSender, as well as utilities for image cropping, upload previews, and batch management.
What's inside Uploady
- React-Uploady is a library designed to handle complex and advanced uploading flows. It provides a set of configurable and extensible building blocks, including components and hooks, allowing developers to customize the upload flow to meet specific project needs.
React-Uploady core features and capabilities
React-Uploady is a modular toolkit for file uploads that supports a wide range of functionalities. Key features include:
- Single and multiple file uploads
- Upload progress tracking
- Aborting running uploads (single, batch, or all)
- Retrying failed or cancelled uploads
- Image and video previews
- Dynamic update of upload parameters (e.g., headers)
- Drag & drop support (including folders)
- Paste-to-upload
- Chunked uploads
- Resumable uploads via Tus
Use @rpldy/mock-sender for testing upload flows
The@rpldy/mock-senderpackage provides a mock sender that implements the same interface and events as a real sender. Use this to replace a production sender during testing to verify that the Uploader behaves correctly, handles progress events, and supports abort functionality without needing a live backend.Use the default XHR sender in react-uploady
The@rpldy/senderpackage provides the default XHR sender for the uploader. It is designed to handle standard file uploads with support for tracking upload progress and canceling active requests.Understand @rpldy/chunked-sender capabilities and limitations
The@rpldy/chunked-senderpackage enables chunked uploading. However, it does not support grouped uploads (single XHR request) or URL uploading; in these specific cases, the upload will be handed over to the default@rpldy/sender. For integration specifically within a React application, use@rpldy/chunked-uploadyinstead.Use safe storage wrappers to prevent browser storage errors
@rpldy/safe-storage provides safe versions of
localStorageandsessionStorage. These wrappers prevent the application from throwing errors in environments where storage is restricted or unsupported, such as Safari in private browsing mode.If the browser's storage is unsupported, the package provides no-op versions of the standard Storage API, ensuring the application remains functional without crashing. The API surface is identical to the standard Web Storage API.
Understand Uploady Batch and BatchItem concepts
Uploady organizes uploads into a hierarchy:
- Batch: A group of one or more files handed over to the uploader. Batches have their own set of lifetime events.
- BatchItem: A wrapper around an individual file or URL. Each BatchItem is assigned a unique ID within the uploader instance and has its own specific lifetime events.
Initialize the main Uploady provider
TheUploadyprovider is the primary entry point for the library. It initializes the Uploader and provides the necessary API context for all other Uploady hooks and components to function within the application.Understand the role of the @rpldy/uploader engine
The Uploader acts as the processing and queuing engine for React-Uploady. Its primary responsibilities include:
- Handing data to the sender for upload
- Managing upload items and batches
- Maintaining the internal state of uploads and their statuses
- Triggering external events
- Orchestrating concurrent uploads and grouping items into single requests (when configured)
- Supporting enhancers for custom functionality
When files are processed, the Uploader represents each file as a Batch Item and groups them into a Batch.
Understand @rpldy/life-events pub/sub functionality
@rpldy/life-events provides event pub/sub management that supports return values. This allows registered event handlers to return a response directly back to the code that emitted the event. This is an internal API intended for use within rpldy packages.Integrate image cropping into the Uploady upload flow
The@rpldy/uploady-croppackage allows developers to intercept the Uploady upload flow to provide image cropping functionality before the file is uploaded to the server.Implement a custom file input in Uploady
To take full control over the file input used to initiate uploads, use thecustomInputprop on theUploadycomponent in combination with theuseFileInputhook. WhencustomInputis enabled, Uploady will not render its own input and will instead wait for a ref to be passed touseFileInputfrom a component rendered within theUploadycontext.import Uploady, { useFileInput } from "@rpldy/uploady"; import UploadButton from "@rpldy/upload-button"; import { useRef } from "react"; const ExampleForm = () => { const inputRef = useRef(); // Pass the ref to useFileInput to link this input to Uploady useFileInput(inputRef); return ( <form action="my-server.com/upload" method="POST"> <input type="file" name="testFile" style={{ display: "none" }} ref={inputRef}/> </form> ); }; const App = () => { return ( <section> {/* The customInput prop tells Uploady to use a provided ref instead of its own input */} <Uploady customInput> <ExampleForm/> <UploadButton/> </Uploady> </section> ); };