react-filezone
Version:
filezone: A Robust, Flexible React File Upload Library with Advanced Features and Seamless User Experience
59 lines (56 loc) • 1.93 kB
TypeScript
import * as axios from 'axios';
interface getRootFileZoneProps {
onDrop: (event: React.DragEvent<HTMLDivElement>) => void;
onDragEnter: (event: React.DragEvent<HTMLDivElement>) => void;
onDragLeave: (event: React.DragEvent<HTMLDivElement>) => void;
onDragOver: (event: React.DragEvent<HTMLDivElement>) => void;
onClick: () => void;
}
interface getInputFileZoneProps {
type: string;
multiple: boolean;
accept: string;
max: string;
onChange: (e: React.ChangeEvent<HTMLInputElement>) => void;
}
interface FileState {
id: string;
file: File;
previewUrl?: string;
videoPreviewUrl?: string;
state: {
status: "pending" | "uploading" | "paused" | "completed" | "error" | "cancelled" | "restarted" | "idle";
progress: number;
errors: string[];
};
metadata?: Record<string, any>;
}
interface UseUploadProps {
action: string;
globalConfig?: {
maxConcurrentUploads?: number;
maxFiles?: number;
mode?: "single" | "multiple";
maxFileSize?: number;
allowedFileTypes?: string[];
disabled?: boolean;
};
metadata?: Record<string, any>;
onUploadStart?: (files: FileState[]) => void;
onUploadComplete?: (data: any) => void;
onError?: (error: Error, file: FileState) => void;
headers?: Record<string, string>;
}
declare const useUpload: ({ action, globalConfig, metadata, onUploadStart, onUploadComplete, onError, headers, }: UseUploadProps) => {
acceptedFiles: FileState[];
errors: string[];
getRootProps: () => getRootFileZoneProps;
getInputProps: () => getInputFileZoneProps;
removeFile: (fileId: string) => void;
uploadFile: (fileId: string) => Promise<axios.AxiosResponse<any, any> | undefined>;
isDragActive: boolean;
isValidatingFiles: boolean;
restartUpload: (fileId: string) => void;
disabled: boolean;
};
export { useUpload };