uploadzx
Version:
Browser-only TypeScript upload library with tus integration for resumable uploads
184 lines (142 loc) β’ 4.77 kB
Markdown
> β οΈ **Development Notice**: This library is currently in active development. The stable release is planned for **July 14, 2025**. Use with caution in production environments.
[](https://www.npmjs.com/package/uploadzx)
[](https://www.npmjs.com/package/uploadzx)
[](https://www.typescriptlang.org/)
[](https://opensource.org/licenses/MIT)
A browser-only TypeScript upload library that provides a developer-friendly abstraction over tus-js-client for resumable file uploads with React integration.
- π **Resumable uploads** using tus protocol
- π± **Cross-browser compatibility** including Safari fallback
- β‘ **File System Access API** support for modern browsers
- π― **React integration** with hooks and components
- π **Progress tracking** with detailed upload statistics
- βΈοΈ **Pause, resume, and cancel** functionality
- πΎ **Persistent upload state** using IndexedDB
- π **Queue management** for multiple uploads
- π¨ **UI-agnostic design** - bring your own UI or use our React components
```bash
npm install uploadzx
pnpm add uploadzx
yarn add uploadzx
```
```typescript
import Uploadzx from 'uploadzx';
const uploader = new Uploadzx({
endpoint: 'https://your-tus-endpoint.com/files',
maxConcurrent: 3,
filePickerOptions: {
multiple: true,
useFileSystemAccess: true,
}
}, {
onProgress: (progress) => {
console.log(`${progress.fileId}: ${progress.percentage}%`);
},
onComplete: (fileId, tusUrl) => {
console.log(`Upload completed: ${tusUrl}`);
},
onError: (fileId, error) => {
console.error(`Upload error for ${fileId}:`, error);
}
});
// Pick files and start uploading
await uploader.pickAndUploadFiles();
```
```tsx
import { UploadzxProvider, useUploadzxContext } from 'uploadzx/react';
function App() {
return (
<UploadzxProvider
options={{
endpoint: 'https://your-upload-server.com/upload',
chunkSize: 1024 * 1024,
autoStart: true,
}}
>
<UploadComponent />
</UploadzxProvider>
);
}
function UploadComponent() {
const { pickAndUploadFiles, uploadStates } = useUploadzxContext();
return (
<div>
<button onClick={pickAndUploadFiles}>Upload Files</button>
{Object.entries(uploadStates).map(([fileId, state]) => (
<div key={fileId}>
{state.file.name} - {state.status} - {state.progress?.percentage}%
</div>
))}
</div>
);
}
```
- `useUploadzxContext()` - Access upload context and state
- `useUploadItem(fileId, state)` - Manage individual upload items
- `useQueueActions()` - Queue management actions
- `useFilePicker(options)` - File picking functionality
- `UploadzxProvider` - Context provider for upload functionality
- `UploadDropzone` - Drag and drop upload component
```typescript
interface UploadzxOptions {
endpoint: string;
chunkSize?: number;
maxConcurrent?: number;
autoStart?: boolean;
filePickerOptions?: {
multiple?: boolean;
useFileSystemAccess?: boolean;
accept?: string;
};
}
```
```typescript
interface UploadzxEvents {
onProgress?: (progress: UploadProgress) => void;
onComplete?: (fileId: string, tusUrl: string) => void;
onError?: (fileId: string, error: Error) => void;
onStateChange?: (fileId: string, state: UploadState) => void;
}
```
- **Chrome/Edge**: Full support with File System Access API
- **Firefox**: Full support with fallback file picker
- **Safari**: Full support with Safari-specific optimizations
- **Mobile browsers**: Supported with appropriate fallbacks
The project includes comprehensive examples:
```bash
pnpm examples:install
pnpm example:react
pnpm example:vanilla
```
```bash
pnpm install
pnpm build
pnpm dev
pnpm example:react
```
Contributions are welcome! Please feel free to submit a Pull Request.
MIT Β© [uploadzx](https://github.com/Hezx13/uploadzx)