1.8.0 • Published 2 months ago

@rpldy/tus-uploady v1.8.0

Weekly downloads
232
License
MIT
Repository
github
Last release
2 months ago

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)TypeDefaultDescription
versionstring"1.0.0"The tus server version
featureDetectionbooleanfalsewhether to query the server for supported extensions
featureDetectionUrlstringnullURL to query for TUS server feature detection, in case it's different from upload URL
onFeaturesDetected(string[]) => ?TusOptionsvoidcallback to handle the extensions the server broadcasts
resumebooleantruewhether to store information locally on files being uploaded to support resuming
deferLengthbooleanfalsedefer sending file length to server (protocol)
overrideMethodbooleanfalsewhether to use X-HTTP-Method-Override header instead of PATCH
sendDataOnCreatebooleanfalsesend first chunk with create request (protocol)
storagePrefixstring"__rpldy-tus__"the key prefix to use for persisting resumable info about files
lockedRetryDelaynumber2000milliseconds to wait before retrying a locked (423) resumable file
forgetOnSuccessbooleanfalsewhether to remove URL from localStorage when upload finishes successfully
ignoreModifiedDateInStoragebooleanfalseignore File's modified date when creating key for storage
resumeHeadersRecord<string, string>nullHeaders 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>);
 
1.8.0

2 months ago

1.8.0-rc.0

2 months ago

1.7.1

4 months ago

1.7.0

4 months ago

1.7.0-rc.1

5 months ago

1.7.0-rc.0

5 months ago

1.6.1

5 months ago

1.6.0

7 months ago

1.6.0-rc.0

7 months ago

1.5.0-rc.0

8 months ago

1.5.0-rc.1

8 months ago

1.5.0-rc.2

8 months ago

1.5.0-rc.3

8 months ago

1.5.0-rc.4

8 months ago

1.5.0-rc.5

8 months ago

1.5.0

7 months ago

1.6.1-rc.2

6 months ago

1.6.1-rc.0

6 months ago

1.6.1-rc.1

6 months ago

1.4.2-alpha.0

1 year ago

1.4.1

1 year ago

1.4.1-rc.0

1 year ago

1.4.0

1 year ago

1.4.0-rc.0

1 year ago

1.4.0-rc.1

1 year ago

1.3.1

1 year ago

1.2.0

2 years ago

1.3.0-rc.2

1 year ago

1.3.0-rc.3

1 year ago

1.3.0-rc.0

1 year ago

1.3.0-rc.1

1 year ago

1.3.0

1 year ago

1.1.0

2 years ago

1.0.1

2 years ago

1.1.0-rc.1

2 years ago

1.1.0-rc.0

2 years ago

1.0.0

2 years ago

0.18.3

2 years ago

0.18.1

2 years ago

0.18.2

2 years ago

0.18.0

2 years ago

0.17.2

2 years ago

0.17.3

2 years ago

0.17.4

2 years ago

0.17.5

2 years ago

0.17.0

2 years ago

0.17.1

2 years ago

0.16.1

2 years ago

0.16.2

2 years ago

0.15.0

2 years ago

0.16.0

2 years ago

0.14.2

2 years ago

0.14.0

3 years ago

0.14.1

3 years ago

0.13.6

3 years ago

0.13.5

3 years ago

0.13.4

3 years ago

0.13.3

3 years ago

0.13.1

3 years ago

0.13.2

3 years ago

0.13.0

3 years ago

0.12.1

3 years ago

0.12.0

3 years ago

0.11.5

3 years ago

0.11.6

3 years ago

0.11.4

3 years ago

0.11.2

3 years ago

0.11.3

3 years ago

0.11.3-alpha.0

3 years ago

0.11.2-alpha.0

3 years ago

0.11.0

3 years ago

0.11.1

3 years ago

0.10.0

3 years ago

0.9.0

3 years ago

0.8.3

3 years ago

0.8.2

3 years ago

0.8.1

3 years ago

0.8.0

3 years ago

0.7.4

3 years ago

0.7.3

3 years ago

0.7.2

3 years ago

0.7.1

4 years ago

0.7.0

4 years ago

0.6.0

4 years ago

0.5.0

4 years ago

0.4.1

4 years ago

0.4.0

4 years ago

0.3.2

4 years ago

0.3.0

4 years ago

0.3.1

4 years ago

0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago