bangnokia / laravel-bunny-storage
Use Bunny Storage in Laravel application
Installs: 13 039
Dependents: 0
Suggesters: 0
Security: 0
Stars: 6
Watchers: 2
Forks: 1
Open Issues: 0
pkg:composer/bangnokia/laravel-bunny-storage
Requires
- illuminate/filesystem: ^10.46|^11|^12
- illuminate/support: ^10.46|^11|^12
- league/flysystem-path-prefixing: ^3.3
- platformcommunity/flysystem-bunnycdn: ^3.3
Requires (Dev)
- laravel/pint: ^v0.2.4|^1.27
- orchestra/testbench: ^8.0|^9.0|^10.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
README
Bunny Storage for Laravel
This package is just a wrapper for Laravel of the flysystem-bunnycdn package for simple integration with Laravel.
Installation
composer require bangnokia/laravel-bunny-storage
Configuration
This package automatically register the service provider and the storage disk for the driver bunny. You can configure the disk in config/filesystems.php:
'bunny' => [ 'driver' => 'bunny', 'storage_zone' => env('BUNNY_STORAGE_ZONE'), 'api_key' => env('BUNNY_API_KEY'), 'region' => env('BUNNY_REGION', \PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion::DEFAULT), 'token_auth_key' => env('BUNNY_TOKEN_AUTH_KEY'), // optional if you want to generate temporaryUrls 'pull_zone' => env('BUNNY_PULL_ZONE', ''), // optional if you want to access the file publicly 'root' => '', // optional, you could set a specific folder for upload like '/uploads' ],
and remember to add the environment variables in your .env file:
BUNNY_STORAGE_ZONE=your-storage-zone-name BUNNY_API_KEY=your-api-key (it's password in bunny) #BUNNY_REGION=your-region (optional) #BUNNY_PULL_ZONE="https://your-pull-zone-url" (optional if you want to access the file publicly) #BUNNY_TOKEN_AUTH_KEY=your-key (optional, CDN > Security > Token authentication > Url token authentication key)
Usage
Storage::disk('bunny')->put('index.html', '<html>Hello World</html>'); return response(Storage::disk('bunny')->get('index.html'));
Streaming Support
This package includes streaming support for large file uploads, which significantly reduces memory usage.
Memory Efficient Uploads
When uploading large files (e.g., database backups, videos), the streaming adapter automatically:
- Detects when a file stream/resource is provided
- Streams the file directly to BunnyCDN without loading into memory
- Reduces memory usage from O(file_size) to O(buffer_size)
Example: Large File Upload
// Efficient streaming - memory stays low (~8-16MB buffer) $stream = fopen('/path/to/large-file.zip', 'r'); Storage::disk('bunny')->put('backup.zip', $stream); fclose($stream); // This also works with writeStream Storage::disk('bunny')->writeStream('backup.zip', $stream);
Regions
For a full region list, please visit the BunnyCDN API documentation page.
flysystem-bunnycdn also comes with constants for each region located within PlatformCommunity\Flysystem\BunnyCDN\BunnyCDNRegion.
# Europe BunnyCDNRegion::FALKENSTEIN = 'de'; BunnyCDNRegion::STOCKHOLM = 'se'; # United Kingdom BunnyCDNRegion::UNITED_KINGDOM = 'uk'; # USA BunnyCDNRegion::NEW_YORK = 'ny'; BunnyCDNRegion::LOS_ANGELAS = 'la'; # SEA BunnyCDNRegion::SINGAPORE = 'sg'; # Oceania BunnyCDNRegion::SYDNEY = 'syd'; # Africa BunnyCDNRegion::JOHANNESBURG = 'jh'; # South America BunnyCDNRegion::BRAZIL = 'br';