1.8.0 • Published 2 months ago

@rpldy/tus-sender v1.8.0

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

TUS Sender

An Uploady sender implementation of the TUS protocol.

Supports version 1.0.0 of the TUS protocol

Under the hood, the tus-sender uses the @rpldy/chunked-sender to upload the files as chunks

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

Installation

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

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

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/upload options params prop into the metadata key/value.

Options

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

All of the chunked-sender options are supported with this sender

When the chunked-sender parallel param is set to > 1, the Concatenation tus extension will be used. It will send the chunks as different parallel requests that are finalized once done.

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

Feature Detection

When the featureDetection option is enabled, the tus-sender will request the supported extensions' info from the server.

In case there are options that aren't supported by the extensions list the server provides, they will be turned off.

These options are:

  • parallel: requiring the concatenation extension
  • sendDataOnCreate: requiring the creation_with_upload extension
  • deferLength: requiring the creation_defer_length extension

When onFeaturesDetected callback is provided, the responsibility to turn off options that aren't supported is handed over to the callback. The object returned by the callback will be merged with options being used, overriding them as needed.

For feature detection to work, when the TUS server is served from a different origin than the page making the request, the server must allow these headers: Tus-Extension and Tus-Version to be read over CORS. Otherwise, it will not work and feature detection will be skipped.

Example

import React, { useCallback, useEffect, useRef } from "react";
import createUploader from "@rpldy/uploader";
import getTusEnhancer from "@rpldy/tus-sender";

export const App = () => {
	const inputRef = useRef(null);
	const uploaderRef = useRef(null);

	useEffect(() => {
		const tusEnhancer = getTusEnhancer({
            parallel: 2,                
		});

		uploaderRef.current = createUploader({
			enhancer: tusEnhancer,
			destination: {url: "my-tus-server.com"},
			params: {
				source: "rpldy",		
			}
		});
	}, []);

	const onClick = useCallback(() => {
		const input = inputRef.current;
		if (input) {
			input.value = "";
			input.click();
		}
	}, []);

	const onInputChange = useCallback(() => {
		uploaderRef.current?.add(inputRef.current?.files);
	}, []);

	return <div>
		<input type="file" ref={inputRef} style={{ display: "none" }} onChange={onInputChange}/>
		<button id="upload-button" onClick={onClick}>Upload with TUS</button>
	</div>
};

Events

The TUS Sender exposes a RESUME_START event. See uploader events section on more info regarding how to register for events.

TUS_EVENTS.RESUME_START

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

This event is cancellable

The event handler receives a ResumeStartEventData object

1.8.0

2 months ago

1.8.0-rc.0

2 months ago

1.7.1

5 months ago

1.7.0

5 months ago

1.7.0-rc.1

5 months ago

1.7.0-rc.0

5 months ago

1.6.1

6 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

8 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.0

3 years ago

0.11.5

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.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.0

4 years ago