useRequestPreSend
Packageβ
Installationβ
- npm
- Yarn
- pnpm
npm install @rpldy/uploady
yarn add @rpldy/uploady
pnpm add @rpldy/uploady
Detailsβ
type useRequestPreSend = (cb: (data: PreSendData) =>
PreSendResponse | boolean | Promise<PreSendResponse | boolean> | Promise<boolean>) => void;
- See: PreSendResponse
- See: PreSendData
note
Event Hook - BATCH-START
Called before a group of items is going to be uploaded Group will contain a single item unless "grouped" option is set to true (default = false).
Handler receives the item(s) in the group and the upload options that were used. The handler can change data inside the items and in the options by returning different data than received. See simple example below or this more detailed guide.
info
This event is cancellable
import { useRequestPreSend } from "@rpldy/uploady";
const MyComponent = () => {
useRequestPreSend(({ items, options }) => {
let method = options.method;
if (options.destination.url.startsWith("https://put-server")) {
method = "PUT";
}
return {
options: { method } //will be merged with the rest of the options
};
});
//...
};