ChunkedUploady
Packageβ
Installationβ
- npm
- Yarn
- pnpm
npm install @rpldy/chunked-uploady
yarn add @rpldy/chunked-uploady
pnpm add @rpldy/chunked-uploady
Propsβ
Name (* = mandatory) | Type | Default | Description |
---|---|---|---|
chunked | boolean | true | chunk uploads. setting to false will return to default sending behavior |
chunkSize | number | 5242880 | the chunk size. relevant when uploaded file is larger than the value |
retries | number | 0 | how many times to retry sending a failed chunk |
parallel | number | 0 | how many (chunk) requests to send simultaneously |
In addition, all UploadOptions props can be passed to ChunkedUploady.
See: Uploady documentation for detailed list of upload options.
retriesβ
It's possible to have chunked uploads retry in case of failure. By default, one chunk failing once will cause the entire upload to error.
Eventsβ
Chunked Sender makes it possible to handle chunk life-time events. See uploader events section on more info regarding how to register for events.
CHUNK_EVENTS.CHUNK_STARTβ
Triggered when a chunk is about to be sent to the server
This event is cancellable
The event handler may return an object with the following shape:
interface ChunkedOptions {
chunked?: boolean;
chunkSize?: number;
retries?: number;
parallel?: number;
}
type StartEventResponse = {
url: string,
sendOptions: ChunkedOptions
}
CHUNK_EVENTS.CHUNK_FINISHβ
Triggered when a chunk has finished uploading
Item Errorβ
In case of chunk upload error in conjunction of using the ITEM_ERROR or the useItemErrorListener hook, it is possible to access the error information returned from the server like so:
import { useItemErrorListener } from "@rpldy/uploady";
const MyComponent = () => {
useItemErrorListener((item) => {
console.log(`item ${item.id} failed - status code:`, item.uploadResponse.chunkUploadResponse.status); //the status code returned by the server on the failed chunk
console.log(`item ${item.id} failed - msg:`, item.uploadResponse.chunkUploadResponse.response); //the response data (if) sent by the server on the failed chunk
});
//...
};