- How do I integrate league/flysystem with Laravel’s Storage facade?
- Use the `spatie/laravel-flysystem` bridge to register Flysystem adapters with Laravel’s `Storage::disk()`. Configure your adapters in `config/filesystems.php` and bind them to Laravel’s service container. This lets you replace or extend Laravel’s built-in storage system while keeping the same API.
- Does league/flysystem support AWS S3, Google Cloud Storage, and Azure Blob Storage?
- Yes, it supports all major cloud providers via adapters like `league/flysystem-aws-s3-v3`, `league/flysystem-gcs`, and `league/flysystem-azure-blob-storage`. Each adapter uses the latest SDKs (e.g., AWS SDK v3) and follows Laravel’s configuration patterns for credentials and endpoints.
- Can I use league/flysystem for SFTP or FTP storage in Laravel?
- Absolutely. Install `league/flysystem-sftp` or `league/flysystem-ftp` and configure them in Laravel’s `filesystems.php`. These adapters handle connection pooling, retries, and error normalization. For production, ensure your server has PHP extensions like `phpseclib` for SFTP.
- What Laravel versions does league/flysystem officially support?
- The package works with Laravel 9+ and PHP 8.1+. For Laravel 10+, ensure you’re using Flysystem 3.x, which includes fixes for PHP 8.3+ compatibility. The `spatie/laravel-flysystem` bridge handles Laravel-specific integrations like config publishing and service provider binding.
- How do I handle file operations across multiple storage backends (e.g., S3 + local cache)?
- Use Flysystem’s `Filesystem` class to create a hybrid setup. For example, instantiate two adapters (S3 and local) and chain operations or use a caching layer like `league/flysystem-cache`. Laravel’s `Storage` facade can also delegate to different Flysystem instances based on disk names.
- Are there performance considerations for large-scale file operations (e.g., 10K+ files)?
- Yes. For bulk operations, use chunking (e.g., `listContents()` with pagination) and async adapters like `league/flysystem-aws-s3-v3` with the `S3Client` configured for parallel requests. Benchmark operations and consider adding a Redis cache layer for metadata (e.g., file hashes, sizes).
- How do I implement retries or fallbacks if S3 fails (e.g., fallback to local storage)?
- Use a custom `Filesystem` wrapper with a `FilesystemAdapter` that implements retry logic via `league/flysystem-cached-adapter` or `spatie/flysystem-circuit-breaker`. For fallbacks, create a `CompositeFilesystem` that tries S3 first, then local storage if the primary fails.
- Does league/flysystem work with Laravel’s queue system for async file processing?
- Yes, you can dispatch jobs (e.g., `UploadFileJob`) that use Flysystem to handle file operations asynchronously. Store the job payload in a queue (e.g., Redis) and process it later. This is useful for large uploads or background tasks like image resizing.
- What are the alternatives to league/flysystem for Laravel storage abstraction?
- Alternatives include Laravel’s built-in `Storage` facade (limited to local, S3, FTP), `spatie/laravel-medialibrary` (for media management), or vendor-specific SDKs like AWS SDK. However, Flysystem stands out for its adapter ecosystem, framework-agnostic design, and seamless Laravel integration via `spatie/laravel-flysystem`.
- How do I secure sensitive files (e.g., encrypt before uploading to S3) with league/flysystem?
- Use Flysystem’s `EncryptedFilesystem` adapter (e.g., `league/flysystem-encrypted`) to encrypt files client-side before uploading. For S3, enable server-side encryption (SSE-S3) via the adapter’s config. Laravel’s `Storage` facade can also wrap Flysystem with encryption middleware for consistent security policies.