bangnokia / laravel-bunny-storage
在 Laravel 应用中使用 Bunny Storage
v1.3.3
2024-04-28 11:20 UTC
Requires
- illuminate/filesystem: ^10.46|^11
- illuminate/support: ^10.46|^11
- league/flysystem-path-prefixing: ^3.3
- platformcommunity/flysystem-bunnycdn: ^3.3
README
Bunny Storage for Laravel
此包只是 Laravel 的 flysystem-bunnycdn 包的包装,用于与 Laravel 简单集成。
安装
composer require bangnokia/laravel-bunny-storage
配置
此包会自动注册服务提供者和驱动 bunny
的存储磁盘。您可以在 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), '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' ],
并记得在您的 .env
文件中添加环境变量
BUNNY_STORAGE_ZONE=your-storage-zone BUNNY_API_KEY=your-api-key #BUNNY_REGION=your-region #BUNNY_PULL_ZONE=your-pull-zone
使用
Storage::disk('bunny')->put('index.html', '<html>Hello World</html>'); return response(Storage::disk('bunny')->get('index.html'));
区域
有关完整区域列表,请访问 BunnyCDN API 文档页面。
flysystem-bunnycdn
还包含每个区域的常量,位于 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';