npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@rpldy/tus-uploady

v1.8.0

Published

wrapper&context component to expose and provide react-uploady functionality with TUS protocol support

Downloads

1,321

Readme

Tus Uploady

This package is provided as a convenient alternative to the main Uploady package. To be used in case resumable (tus) upload is required.

The package wraps the tus-sender

Additional information about tus functionality can be found the tus-sender README.

The best place to get started is at our: React-Uploady Documentation Website

Props

| Name (* = mandatory) | Type | Default | Description | |-----------------------------|---------------------------|---------------------|------------------------------------------------------------------------------------------------------------------------| | version | string | "1.0.0" | The tus server version | | featureDetection | boolean | false | whether to query the server for supported extensions | | featureDetectionUrl | string | null | URL to query for TUS server feature detection, in case it's different from upload URL | | onFeaturesDetected | (string[]) => ?TusOptions | void | callback to handle the extensions the server broadcasts | | resume | boolean | true | whether to store information locally on files being uploaded to support resuming | | deferLength | boolean | false | defer sending file length to server (protocol) | | overrideMethod | boolean | false | whether to use X-HTTP-Method-Override header instead of PATCH | | sendDataOnCreate | boolean | false | send first chunk with create request (protocol) | | storagePrefix | string | "__rpldy-tus__" | the key prefix to use for persisting resumable info about files | | lockedRetryDelay | number | 2000 | milliseconds to wait before retrying a locked (423) resumable file | | forgetOnSuccess | boolean | false | whether to remove URL from localStorage when upload finishes successfully | | ignoreModifiedDateInStorage | boolean | false | ignore File's modified date when creating key for storage | | resumeHeaders | Record<string, string> | null | Headers to use for the resume check (HEAD) request |

In addition, all UploadOptions props can be passed to TusUploady. In order to override configuration passed to the parent Uploady component. See Uploady documentation for detailed list of upload options.

All of the chunked-sender options are supported as well

Params prop that is set on the Destination or upload options is serialized (encoded according to Tus protocol) and sent as the value of the Upload-Metadata header.

Custom headers set on the Destination will be sent (and override existing headers) with the Creation request

Installation

#Yarn:
  $ yarn add @rpldy/tus-uploady

#NPM:
  $ npm i @rpldy/tus-uploady

TUS Protocol

On top of the Core Protocol, Uploady supports the following extensions:

It also supports the Upload-Metadata header and will turn the destination params prop into the metadata key/value.

Hooks

useTusResumeStartListener

Called before the (HEAD) request is issued on behalf of a potentially resumeable upload.

This event is cancellable

Receives an object with:

  • url: the URL the resume request will be sent to
  • item: the BatchItem being sent
  • resumeHeaders: an optional object that was passed to the TusUploady props

May return false to cancel the resume, nothing, or an object with url property to overwrite the URL the request will be sent to. And/Or a resumeHeaders object that will be merged with the optional object passed as a prop to TusUploady.

import React from "react";
import { useTusResumeStartListener } from "@rpldy/tus-uploady";

const MyComponent = () => {
    useTusResumeStartListener(({ url, item, resumeHeaders }) => {
        return cancelResume ? false : {
            resumeHeaders: {
                "x-another-header": "foo",
                "x-test-override": "def"
            }
        }
    });

	//...
};

useClearResumableStore

By default, the tus-sender will store the URLs for uploaded files so it can query the server for their status and skip chunks that are indicated as uploaded.

The URLs are persisted to local storage. This hooks allows you to clear the URLs that were previously persisted.

import React, { useCallback } from "react";
import { useClearResumableStore } from "@rpldy/tus-uploady"; 

const MyComponent = () => {
	const clearResumables = useClearResumableStore();
    
    const onClear = useCallback(() => {
      clearResumables();
    }, [clearResumables]);

    return <button onClick={onClear}>Clear Store</button>;
}; 

Example

 import React from "react";
 import TusUploady from "@rpldy/tus-uploady";
 import UploadButton from "@rpldy/upload-button";
 
 const App = () => (<TusUploady
     destination={{ url: "https://my-tus-server/upload" }}
     chunkSize={2142880}
     sendDataOnCreate>
     <UploadButton/>
 </TusUploady>);