A simple wrapper arround bunny cdn laravel filesystem adapter
itsemon245/laravel-bunny is a Laravel package for a simple wrapper arround bunny cdn laravel filesystem adapter.
It currently has 7 GitHub stars and 4.809 downloads on Packagist (latest version v1.2.2).
Install it with composer require itsemon245/laravel-bunny.
Discover more Laravel packages by itsemon245
or browse all Laravel packages to compare alternatives.
Last updated
A simple package that provides a new Storage Driver for bunny CDN using their Filesystem Adapter.
composer require itsemon245/laravel-bunny
Add a new entry for disks in config/filesystems.php using the following example.
'bunny'=>[
'driver' => 'bunny',
'storage_zone' => env('BUNNYCDN_STORAGE_ZONE', 'my-storage-zone'),# Name of your storage zone
'pull_zone' => env('BUNNYCDN_PULL_ZONE', 'https://random.b-cdn.net'),#Pull Zone URL
'api_key' => env('BUNNYCDN_API_KEY'), # Use one of the password found in the storage zone.
'region' => env('BUNNYCDN_REGION', \Itsemon245\LaravelBunny\Region::DEFAULT),
'connect_timeout' => 5, # Seconds allowed to establish the storage connection
'timeout' => 30, # Maximum seconds for non-upload storage requests
'upload_timeout_min' => 20, # Minimum automatic upload timeout in seconds
'upload_timeout_max' => 600, # Maximum automatic upload timeout in seconds
'upload_bytes_per_second' => 1048576, # Expected upload speed used to size the timeout
'upload_timeout_overhead' => 10, # Extra seconds added to automatic upload timeouts
'root'=> 'my-files',#Optional, all files will be stored under this directory if specified
]
Uploads use a bounded timeout based on their content size. To set a fixed timeout for every upload on a disk, set upload_timeout. To override one upload, pass bunny_upload_timeout to Laravel's put options:
Storage::disk('bunny')->put('audios/final.mp3', $contents, [
'bunny_upload_timeout' => 600,
]);
[!NOTE] Don't use the api key from your account settings, it does not work. Use one of the passwords found under Storage Zone > FTP & API Access section
Usage is pretty simple.
//Storing file
Storage::disk('bunny')->put('new-file.txt', 'hello-world');
//Retrieving url
$url = Storage::disk('bunny')->url('new-file.txt');# https://random.b-cdn.net/my-files/new-file.txt
You can also skip calling the disk method everytime if you set FILESYSTEM_DISK to bunny in you .env. Then you can do something simple like.
//Storing file
Storage::put('new-file.txt', 'hello-world');
//Retrieving url
$url = Storage::url('new-file.txt');# https://random.b-cdn.net/my-files/new-file.txt
For a full region list, please visit the BunnyCDN API documentation page.
The package also comes with a set of region constants to use
use Itsemon245\LaravelBunny\Region;
# Default
Region::DEFAULT = 'de';
# Europe
Region::FALKENSTEIN = 'de';
Region::STOCKHOLM = 'se';
# United Kingdom
Region::UNITED_KINGDOM = 'uk';
# USA
Region::NEW_YORK = 'ny';
Region::LOS_ANGELAS = 'la';
# SEA
Region::SINGAPORE = 'sg';
# Oceania
Region::SYDNEY = 'syd';
# Africa
Region::JOHANNESBURG = 'jh';
# South America
Region::BRAZIL = 'br';