Download the PHP package netipar/laravel-chunky without Composer
On this page you can find all versions of the php package netipar/laravel-chunky. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download netipar/laravel-chunky
More information about netipar/laravel-chunky
Files in netipar/laravel-chunky
Package laravel-chunky
Short Description Chunk-based file upload package for Laravel with event-driven architecture, resume support, batch upload, and framework-agnostic frontend clients for Vue 3, React, Alpine.js, and Livewire.
License MIT
Homepage https://github.com/NETipar/laravel-chunky
Informations about the package laravel-chunky
Chunky for Laravel
Chunk-based file upload package for Laravel with event-driven architecture, resume support, and framework-agnostic frontend clients for Vue 3, React, Alpine.js, and Livewire. Upload large files reliably over unstable connections.
Table of contents
- Quick example
- Requirements
- 5-minute quickstart
- Production deployment checklist
- Livewire
- Frontend packages
- Usage
- Batch upload (multiple files)
- Authentication & authorization
- Context setup
- Listening to events
- Broadcasting (Laravel Echo)
- Using the facade
docs/configuration.md- Error handling
Additional documentation:
docs/configuration.md— full config reference + deployment recipes- UPGRADE.md — minor-release migration notes (the package is in
0.x) - SECURITY.md — supported versions and reporting policy
- CHANGELOG.md — release history
Quick Example
Requirements
- PHP 8.2+
- Laravel 11, 12 or 13
5-Minute Quickstart
Production Deployment Checklist
- [ ] Auth middleware on
chunky.routes.middleware(e.g.['api', 'auth:sanctum']) - [ ] Queue worker running for
AssembleFileJob(don't run onsync) - [ ] Cache driver that supports
Cache::lock()if usingchunky.lock_driver = 'cache'(Redis / Memcached / DB / DynamoDB; notarrayorfile) - [ ]
CHUNKY_BROADCASTING=trueif real-time UI updates are needed (requires Echo + a WebSocket server) - [ ]
chunky.staging_directoryset to a path with enough free space if accepting uploads larger than/tmp(cloud-disk targets buffer the full file locally before upload) - [ ]
chunky.metadata.max_keysandchunky.max_files_per_batchtuned for your DOS profile - [ ] *`chunky.metrics.`** wired to Datadog / Prometheus / your observability stack
- [ ]
chunky:cleanupscheduled daily (auto-scheduled ifauto_cleanup = true) - [ ] Custom
Authorizerbound if the default ownership check (auth user_id == upload user_id) doesn't fit your access model - [ ]
routes/channels.phpauto-registered (default) or hand-written if you setchunky.broadcasting.register_channels = false
Installation
Backend
Publish the config file:
Run the migrations (for database tracker):
Frontend
Install the package for your framework:
The
@netipar/chunky-corepackage is automatically installed as a dependency of all framework packages.
Livewire
No npm package needed. The Livewire component uses Alpine.js under the hood and is included in the Composer package. Just add the component to your Blade template:
Frontend Packages
| Package | Framework | Peer Dependencies |
|---|---|---|
@netipar/chunky-core |
None (vanilla JS/TS) | - |
@netipar/chunky-vue3 |
Vue 3.4+ | vue |
@netipar/chunky-react |
React 18+ / 19+ | react |
@netipar/chunky-alpine |
Alpine.js 3+ | - |
Usage
How It Works
- Frontend initiates an upload with file metadata
- Backend returns an
upload_id,chunk_size, andtotal_chunks - Frontend slices the file and uploads chunks in parallel with SHA-256 checksums
- Backend stores each chunk, verifies integrity, tracks progress
- When all chunks arrive, an
AssembleFileJobmerges them on the queue - Events fire at each step -- hook in your own listeners
CSRF Protection
The frontend client automatically reads the XSRF-TOKEN cookie (set by Laravel) and sends it as the X-XSRF-TOKEN header. No manual CSRF setup is needed in most Laravel applications.
If you need a custom token header, use setDefaults():
Config Isolation
For multiple upload scopes on the same page:
API Endpoints
The package registers seven routes (configurable prefix/middleware):
| Method | Endpoint | Purpose |
|---|---|---|
POST |
/api/chunky/upload |
Initiate upload |
POST |
/api/chunky/upload/{uploadId}/chunks |
Upload a chunk |
GET |
/api/chunky/upload/{uploadId} |
Get upload status |
DELETE |
/api/chunky/upload/{uploadId} |
Cancel upload |
POST |
/api/chunky/batch |
Initiate batch |
POST |
/api/chunky/batch/{batchId}/upload |
Add file to batch |
GET |
/api/chunky/batch/{batchId} |
Get batch status |
HTTP status codes
| Code | When |
|---|---|
201 Created |
Upload or batch initiated |
200 OK |
Chunk accepted, status fetched |
204 No Content |
Cancel succeeded |
404 Not Found |
Upload/batch doesn't exist — or the caller isn't its owner (intentional, prevents probe attacks) |
409 Conflict |
Late chunk against a cancelled / completed / failed / assembling upload |
410 Gone |
Upload has expired |
422 Unprocessable Entity |
Validation error (missing field, invalid file_name, batch in terminal state, etc.) |
503 Service Unavailable |
Upload temporarily contended on the lock; client may safely retry (idempotent) |
Vue 3
React
Alpine.js
Livewire
Listen for the upload completion in your Livewire parent component:
Core (Framework-agnostic)
Batch Upload (Multiple Files)
Upload multiple files as a batch and get a single event when all files are done.
Vue 3
React
Alpine.js
Core (Framework-agnostic)
How Batch Works
- Frontend calls
POST /api/chunky/batchwithtotal_filescount - Backend creates a batch record and returns
batch_id - For each file, frontend calls
POST /api/chunky/batch/{batchId}/uploadto initiate - Chunks are uploaded normally via
POST /api/chunky/upload/{uploadId}/chunks - When each file's assembly completes, the batch counter increments atomically
- When all files are done,
BatchCompleted(orBatchPartiallyCompleted) event fires
Every upload creates a batch — even a single file becomes a batch of 1. This ensures consistent behavior: every upload gets a batchId and fires BatchCompleted. useBatchUpload is the single entry point for all uploads.
Failure policy: Lenient -- if a file fails, other files continue. The batch ends with PartiallyCompleted status.
Sequential Batches with enqueue()
upload() throws if a batch is already in progress on the same BatchUploader instance. For UIs that accept files faster than they can upload (multi-paste, drag-while-uploading), use enqueue() instead:
If you cancel() or destroy() the uploader before a queued batch starts, its promise rejects with a clear error message. The Vue 3 / React / Alpine wrappers all expose enqueue as a sibling of upload.
Authentication & Authorization
Authentication
By default, upload endpoints use only the api middleware. To protect them with authentication, update routes.middleware in config/chunky.php:
This applies to all routes (initiate, upload chunk, cancel, status, batch). No custom request or controller override is needed.
Authorization (per-upload, per-batch)
When auth is active, the package automatically enforces ownership: an authenticated caller can only access uploads / batches they created (the user_id captured at initiation time). Non-owners see a 404 (not 403) so upload IDs can't be probed.
The check is delegated to a swappable Authorizer interface:
The default DefaultAuthorizer does plain ownership: auth()->id() === upload->userId, with anonymous uploads (no user_id) accessible to everyone (backward compat).
Custom Authorizer (admin overrides, team access, …)
Bind your own implementation in AppServiceProvider::register():
The same Authorizer is used by the broadcast channel auth callbacks (routes/channels.php, auto-registered when broadcasting.enabled = true) — HTTP and WebSocket access stay in sync.
user_id is portable
The chunked_uploads.user_id and chunky_batches.user_id columns are string type since v0.14, so any user-id shape works out of the box: auto-increment integers, UUIDs, ULIDs, or arbitrary strings. The package never does arithmetic on user_id, only string equality comparisons.
Quick Context Setup
For the most common case -- validate and move the file to a directory:
This registers a context that validates the file and moves it from the temp directory to uploads/documents/{fileName} after assembly. No event listener needed.
Context-based Validation & Save Callbacks
Contexts define per-upload validation rules and save handlers. You can use class-based contexts (recommended) or inline closures.
Class-based Contexts (Recommended)
Create a context class:
Register via config (config/chunky.php):
Or register manually in your AppServiceProvider:
Inline Closures
For simple cases, you can register contexts inline:
Using Contexts from Frontend
Listening to Events
Register listeners in your EventServiceProvider:
Example listener:
Available Events
| Event | Payload | When | Broadcasts? |
|---|---|---|---|
UploadInitiated |
uploadId, fileName, fileSize, totalChunks | Upload initialized | — |
ChunkUploaded |
uploadId, chunkIndex, totalChunks, progress% | After each successful chunk | — |
ChunkUploadFailed |
uploadId, chunkIndex, exception | On chunk error | — |
FileAssembled |
uploadId, finalPath, disk, fileName, fileSize | After file assembly | — |
UploadCompleted |
upload (UploadMetadata) | Full upload complete | ✅ |
UploadFailed |
upload (UploadMetadata), reason | Save callback failed or assembly job exhausted retries | ✅ |
BatchInitiated |
batchId, totalFiles | Batch created | — |
BatchCompleted |
batchId, totalFiles | All batch files completed | ✅ |
BatchPartiallyCompleted |
batchId, completedFiles, failedFiles, totalFiles | Batch done with failures | ✅ |
Broadcasting (Laravel Echo)
Get real-time notifications when uploads or batches complete. Broadcasting is disabled by default -- enable it in your .env:
Four events are broadcastable: UploadCompleted, UploadFailed, BatchCompleted, and BatchPartiallyCompleted. They use private channels — when chunky.broadcasting.register_channels = true (default), the package auto-registers Broadcast::channel() callbacks that delegate to the bound Authorizer, so the same ownership rules apply on HTTP and WebSocket.
If you set register_channels = false, register them manually in your routes/channels.php:
Vue 3
React
Batch Echo
Core (Framework-agnostic)
User Channel
Instead of subscribing per-upload or per-batch, listen on the user channel to receive all upload events — even after page reload:
The user channel requires authenticated routes (auth:sanctum middleware) and user_id is automatically captured from auth()->id() during upload initiation.
Using the Facade
Configuration
The full configuration reference lives in docs/configuration.md — every key, default, and the common deployment recipes (large videos, S3, authenticated routes, per-chunk progress broadcast). The TL;DR .env:
Publish the config to customise:
The config is grouped into 10 sections (since v0.18): storage, chunks, lifecycle, limits, metadata, locking, idempotency, cache, authorization, broadcasting. Older flat keys were renamed — see UPGRADE.md for the full migration table.
Tracking Drivers
Database (default)
Uses the chunked_uploads table. Best for production -- queryable, reliable, supports status tracking.
Filesystem
Uses JSON metadata files on disk. Zero database dependency -- useful for simple setups.
Error Handling
Examples
- English examples
- Magyar peldak
Testing
Credits
License
The MIT License (MIT). Please see License File for more information.
All versions of laravel-chunky with dependencies
illuminate/support Version ^11.0|^12.0|^13.0
illuminate/http Version ^11.0|^12.0|^13.0
illuminate/routing Version ^11.0|^12.0|^13.0
illuminate/database Version ^11.0|^12.0|^13.0
illuminate/filesystem Version ^11.0|^12.0|^13.0
illuminate/bus Version ^11.0|^12.0|^13.0
illuminate/queue Version ^11.0|^12.0|^13.0