itsemon245/laravel-bunny

A simple wrapper arround bunny cdn laravel filesystem adapter

1.1 2025-01-06 04:48 UTC

This package is auto-updated.

Last update: 2025-01-06 05:09:46 UTC


README

Total Downloads Latest Stable Version License

Laravel Bunny

A simple package that provides a new Storage Driver for bunny CDN using their Filesystem Adapter.

Installation

composer require itsemon245/laravel-bunny

Configuration

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),
      'root'=> 'my-files',#Optional, all files will be stored under this directory if specified
  ]

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

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

List of regions

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';