sopamo/laravel-filepond
All-in-one Laravel backend for FilePond uploads. Provides endpoints for process/revert/patch, supports chunked uploads, stores files temporarily on any Laravel disk, and helps resolve serverIds to paths so you can move files to final storage.
Installation
composer require sopamo/laravel-filepond
Publish the config file:
php artisan vendor:publish --provider="Sopamo\Filepond\FilepondServiceProvider" --tag="filepond-config"
Configure Storage
Edit config/filepond.php to define:
disk (default: public)path (e.g., uploads/filepond)allowed_mime_types (e.g., ['image/*', 'application/pdf'])max_file_size (e.g., 10MB)config/app.php includes Laravel 13's updated service provider and alias configurations if migrating.First Upload Endpoint
Add the route in routes/web.php:
use Sopamo\Filepond\FilepondController;
Route::post('/filepond-upload', [FilepondController::class, 'upload']);
Frontend Integration Include FilePond CSS/JS in your Blade view:
<link href="https://unpkg.com/filepond@^4/dist/filepond.css" rel="stylesheet">
<script src="https://unpkg.com/filepond@^4/dist/filepond.js"></script>
Initialize FilePond with the upload endpoint:
FilePond.registerPlugin(
FilePondPluginImagePreview,
FilePondPluginImageExifOrientation,
FilePondPluginFileValidateType
);
FilePond.setOptions({
server: {
process: '/filepond-upload',
revert: '/filepond-revert',
load: '/filepond-load',
},
});
Basic Upload
Use the default FilepondController for simple drag-and-drop uploads. The package handles:
app/Providers/AppServiceProvider.php boot method is compatible with Laravel 13’s updated container binding syntax.Custom Validation
Extend the FilepondController to add business logic:
// app/Http/Controllers/CustomFilepondController.php
use Sopamo\Filepond\FilepondController;
class CustomFilepondController extends FilepondController
{
public function upload(Request $request)
{
$this->validate($request, [
'file' => ['required', 'mimes:jpeg,png,pdf', 'max:10240'],
'user_id' => 'required|exists:users,id',
]);
return parent::upload($request);
}
}
Chunked Uploads (Large Files)
Configure FilePond for chunked uploads in config/filepond.php:
'chunk_size' => '5MB',
'chunk_upload_url' => '/filepond-chunk-upload',
Implement the chunk handler in your controller:
public function chunkUpload(Request $request)
{
// Logic to handle chunks (e.g., using `league/flysystem`).
}
File Processing Post-Upload
Use Laravel’s stored event to process files:
// app/Providers/AppServiceProvider.php
use Sopamo\Filepond\Events\FileUploaded;
public function boot()
{
FileUploaded::listen(function ($event) {
// Resize images, generate thumbnails, etc.
// Access file path: $event->filePath
});
}
// resources/js/app.js
import FilePond from 'filepond';
import 'filepond/dist/filepond.min.css';
import FilePondPluginImagePreview from 'filepond-plugin-image-preview';
FormRequest for reusable validation:
// app/Http/Requests/FileUploadRequest.php
public function rules()
{
return [
'file' => ['required', 'mimes:jpeg,png', 'max:5120'],
];
}
league/flysystem for cloud storage (S3, etc.):
// config/filepond.php
'disk' => 's3',
config/filesystems.php is updated to match Laravel 13’s default configurations.CORS Issues
// app/Http/Middleware/Cors.php
$allowedOrigins = ['http://your-frontend.com'];
File Overwrites
// config/filepond.php
'filename_generator' => function ($file, $folder, $format, $options) {
return 'custom_' . time() . '.' . $file->getClientOriginalExtension();
},
Missing Revert/Load Endpoints
/filepond-revert and /filepond-load routes. Add them in routes/web.php:
Route::post('/filepond-revert', [FilepondController::class, 'revert']);
Route::get('/filepond-load', [FilepondController::class, 'load']);
Large File Timeouts
max_execution_time and memory_limit if uploading large files:
// config/filepond.php
'chunk_upload_timeout' => 300, // 5 minutes
Laravel 13 Compatibility
composer.json and config/app.php are updated to reflect Laravel 13’s requirements. Pay attention to any changes in service provider bootstrapping or middleware handling.public function upload(Request $request)
{
try {
return parent::upload($request);
} catch (\Exception $e) {
\Log::error('FilePond upload failed: ' . $e->getMessage());
return response()->json(['error' => 'Upload failed'], 500);
}
}
413 Payload Too Large (adjust client_max_body_size in Nginx/Apache)./filepond-upload endpoint to isolate backend issues.Custom Storage Logic
Override the storeFile method in your controller:
protected function storeFile($request, $file)
{
$path = $this->getFilePath($file);
Storage::disk($this->config['disk'])->put($path, file_get_contents($file));
return $path;
}
Pre-Signed URLs (S3) Generate pre-signed URLs for direct uploads to S3:
use Aws\S3\S3Client;
public function upload(Request $request)
{
$s3 = new S3Client([...]);
$url = $s3->getObjectUrl('your-bucket', 'uploads/' . $request->file('file')->getClientOriginalName());
return response()->json(['url' => $url]);
}
Webhook Triggers Dispatch events after upload:
event(new \App\Events\FileUploaded($filePath, $request->user()));
Laravel 13 Event System Ensure your event listeners are registered correctly in Laravel 13’s updated event system:
// app/Providers/EventServiceProvider.php
protected $listen = [
\Sopamo\Filepond\Events\FileUploaded::class => [
\App\Listeners\ProcessUploadedFile::class,
],
];
How can I help you explore Laravel packages today?