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.

Tokens
45K
Snippets
290
Records
352
Agent score
70%

What's inside Uploady

  1. Overview of React-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.
  2. 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
  3. Use @rpldy/mock-sender for testing upload flows

    The @rpldy/mock-sender package 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.
  4. Understand @rpldy/chunked-sender capabilities and limitations

    The @rpldy/chunked-sender package 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-uploady instead.
  5. Use safe storage wrappers to prevent browser storage errors

    @rpldy/safe-storage provides safe versions of localStorage and sessionStorage. 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.

  6. 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.
  7. Initialize the main Uploady provider

    The Uploady provider 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.
  8. 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.

  9. 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.
  10. Integrate image cropping into the Uploady upload flow

    The @rpldy/uploady-crop package allows developers to intercept the Uploady upload flow to provide image cropping functionality before the file is uploaded to the server.
  11. Implement a custom file input in Uploady

    To take full control over the file input used to initiate uploads, use the customInput prop on the Uploady component in combination with the useFileInput hook. When customInput is enabled, Uploady will not render its own input and will instead wait for a ref to be passed to useFileInput from a component rendered within the Uploady context.
    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>
        );
    };