champs-libres/async-uploader-bundle
Symfony bundle that handles asynchronous file uploads, letting you queue and process uploads in the background for smoother UX. Provides integration hooks and configurable storage/processing so uploads don’t block requests.
Installation
composer require champs-libres/async-uploader-bundle
Add to config/app.php under providers:
ChampsLibres\AsyncUploaderBundle\AsyncUploaderBundle::class,
Publish Configuration
php artisan vendor:publish --provider="ChampsLibres\AsyncUploaderBundle\AsyncUploaderBundle" --tag="config"
Configure config/async_uploader.php with your Swift/S3 credentials and storage settings.
First Use Case: Basic Upload Endpoint Add the middleware to your upload route:
Route::post('/upload', [UploadController::class, 'handle'])
->middleware('async.uploader');
Ensure your frontend sends files via multipart/form-data with a temp-url field (auto-generated by the middleware).
Frontend
AsyncUploader JS library (if provided) or manually construct a request with:
const formData = new FormData();
formData.append('file', fileInput.files[0]);
formData.append('temp-url', await fetchTempUrl()); // Optional if middleware auto-generates
fetch('/upload', { method: 'POST', body: formData });
Middleware
temp-url (if provided) or generates a temporary Swift/S3 URL.Backend
job_id for tracking:
{ "job_id": "abc123", "status": "queued" }
AsyncUploaderBundle's Job model to track progress (e.g., Job::find($job_id)->status).// In UploadController
public function handle(Request $request) {
$job = AsyncUploader::upload($request->file('file'));
ProcessUploadJob::dispatch($job->job_id);
return response()->json(['job_id' => $job->job_id]);
}
// config/async_uploader.php
'storage' => env('UPLOAD_DRIVER') === 'swift' ? 'swift' : 's3',
// app/Http/Middleware/ValidateUpload.php
public function handle($request, Closure $next) {
$request->validate([
'file' => 'required|file|mimes:jpg,png|max:10240',
]);
return $next($request);
}
Temp-URL Expiry
temp_url_ttl in config or use shorter-lived URLs with client-side retries.Large File Handling
Job Tracking
Job model may not persist if the upload fails mid-stream.database driver in Laravel).storage.log in config/async_uploader.php to debug Swift/S3 connection issues.async.uploader runs before any validation that might reject the request early.Custom Storage Adapters
Override the default adapter by binding a new ChampsLibres\AsyncUploaderBundle\Storage\AdapterInterface:
// app/Providers/AppServiceProvider.php
public function register() {
$this->app->bind(
StorageAdapterInterface::class,
CustomS3Adapter::class
);
}
Event Listeners
Listen for upload events (e.g., UploadStarted, UploadFailed) to trigger notifications:
// app/Providers/EventServiceProvider.php
protected $listen = [
UploadStarted::class => [UploadLogger::class, 'log'],
];
Frontend Hooks If the bundle includes JS, extend it with custom hooks for progress bars or retries:
AsyncUploader.on('upload:progress', (progress) => {
console.log(`Uploaded ${progress}%`);
});
How can I help you explore Laravel packages today?