Skip to main content

useTusPartStartListener

Package​

@rpldy/tus-uploady

Installation​

npm install @rpldy/tus-uploady

Details​

type useTusPartStartListener: (cb: (data: TusPartStartEventData) => TusPartStartEventResponse) => void;
note

Event Hook - PART_START

Called before a (PATCH) request is issued to upload a chunk (part) of a file.

Receives an object with:

  • url: the URL the PATCH request will be sent to
  • item: the BatchItem being sent
  • headers: the headers that will be sent with the request
  • chunk: the chunk info (start, end, chunkSize)

May return nothing or an object with:

  • url property to overwrite the URL the request will be sent to
  • headers object that will be merged with the headers that will be sent with the request.
import React from "react";
import { useTusPartStartListener } from "@rpldy/tus-uploady";

const MyComponent = () => {
useTusPartStartListener(({ item, chunk, headers, url }) => {
const authHeaderVal = headers["Authorization"];

return {
headers: {
"Authorization": authHeaderVal + "-part-" + (chunk.index + 1),
}
};
});

//...
};