rahulhaque/laravel-filepond
Laravel backend for FilePond uploads: temp storage management, validation, cleanup, and easy persistence. Supports single/multi, chunked & resumable uploads, S3 multipart, third‑party disks, FilePond endpoints (process/patch/head/revert/restore), metadata plugin, and Spatie MediaLibrary.
Installation
composer require rahulhaque/laravel-filepond:"^13.0"
php artisan vendor:publish --provider="RahulHaque\Filepond\FilepondServiceProvider"
php artisan migrate
Frontend Setup Include FilePond JS/CSS in your view and configure the server endpoint:
FilePond.setOptions({
server: {
url: "{{ config('filepond.server.url') }}",
headers: {
'X-CSRF-TOKEN': "{{ csrf_token() }}"
}
}
});
FilePond.create(document.querySelector('input[type="file"]'));
First Upload Create a form with a file input and submit it to a controller:
<form action="{{ route('upload') }}" method="post" enctype="multipart/form-data">
@csrf
<input type="file" name="filepond">
<button type="submit">Upload</button>
</form>
Controller Processing Validate and move the file:
use RahulHaque\Filepond\Facades\Filepond;
public function upload(Request $request) {
$request->validate([
'filepond' => ['required', Rule::filepond(['image', 'max:2000'])]
]);
$fileInfo = Filepond::field($request->filepond)
->moveTo('uploads/' . time());
return redirect()->back()->with('success', 'Uploaded!');
}
config/filepond.php (temporary storage, validation rules, middleware).Filepond::field() as the entry point for all operations.Rule::filepond() for custom validation rules.php artisan filepond:clear for cleanup.Frontend Integration
FilePond.create(inputElement, { chunkUploads: true });
Backend Processing
$fileInfo = Filepond::field($request->file)
->moveTo('path/to/file');
$fileInfos = Filepond::field($request->files)
->moveTo('path/to/files');
Validation
config/filepond.php (applies to all uploads).FormRequest:
$request->validate([
'filepond' => ['required', Rule::filepond(['mimes:jpg,png', 'max:5120'])]
]);
Storage Handling
public disk for permanent storage.Filepond::field($request->file)
->moveTo('path/to/file', 's3');
Chunked Uploads
chunkUploads: true).moveTo() method in Nova tool actions for file attachments.fileInfo.url) to the frontend for preview.fileInfo for direct client-side use:
return response()->json($fileInfo);
filepond table for auditing:
$file = Filepond::field($request->file)->getFile()->getModel();
| Use Case | Implementation Pattern |
|---|---|
| User Avatars | Single file upload with moveTo('avatars/'). |
| Product Galleries | Multiple files with moveTo('galleries/'). |
| Document Uploads | Custom validation (e.g., Rule::filepond(['pdf'])). |
| Resumable Uploads | Enable chunkUploads in JS and use S3/AWS. |
| File Previews | Use getFile() to generate thumbnails. |
Temporary Storage Location
temp_disk is set to a cloud provider (e.g., S3), controller validation fails because files aren’t locally accessible.local disk for temporary storage and validate before moving.File Ownership Checks
checkOwnership: true in field() prevents unauthorized access to temporary files.Chunked Uploads Without S3
php artisan filepond:clear to purge expired chunks.Debugging Missing Files
moveTo()? Check:
storage:link for local storage).soft_delete config (default true).php artisan filepond:clear).Validation Rule Conflicts
Rule::filepond() overrides global rules but fails silently if the file isn’t found (e.g., cloud temp storage).getFile() to check existence.$file = Filepond::field($request->file)->getFile();
\Log::info($file->getClientOriginalName());
ls storage/temp_filepond/
\Log::info(config('filepond.temp_disk')); // Should be 'local' for validation
FilePond.setOptions({ chunkSize: 1024 * 1024 }); // 1MB chunks
Custom Validation Rules
Extend the Rule::filepond() logic in app/Providers/AppServiceProvider:
use RahulHaque\Filepond\Rules\Filepond;
Filepond::extend('custom', function ($attribute, $value, $parameters) {
return $value->getClientSize() < 10 * 1024 * 1024; // 10MB max
});
Override File Naming
Modify the moveTo() behavior by binding to the filepond.moving event:
Filepond::field($request->file)->moveTo('uploads/')
->then(function ($fileInfo) {
// Rename or process further
});
Add Metadata
Use the filepond-plugin-file-metadata plugin and store metadata in the filepond table:
$file = Filepond::field($request->file)->getFile()->getModel();
$file->metadata = json_encode(['exif' => $exifData]);
$file->save();
Webhook Triggers Dispatch events after file processing:
event(new FileUploaded($fileInfo));
Listen in EventServiceProvider:
protected $listen = [
FileUploaded::class => [FileUploadHandler::class],
];
server.url in Config:
Must match your route (default: /filepond/process). Update if using a custom route:
config(['filepond.server.url' => '/custom/process']);
temp_folder Permissions:
Ensure the directory is writable:
chmod -R 755 storage/temp_filepond/
AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY in .env:
AWS_DEFAULT_REGION=us-east-1
soft_delete skips the filepond table but loses audit logs.chunkSize in FilePond JS (e.g., 5MB for slow connections).moveTo() operations for async handling:
Filepond::field($request->files)
->moveTo('uploads/')
->then
How can I help you explore Laravel packages today?