andreinocenti / laravel-file-s3-like
一个用于通过 Laravel 上传、更新、删除、清除类似 S3 存储的包
v1.2
2024-07-24 21:04 UTC
Requires
- php: ^8.2
- illuminate/contracts: ^8.0|^9.0|^10.0|^11.0
- illuminate/http: ^8.0|^9.0|^10.0|^11.0
- illuminate/support: ^8.0|^9.0|^10.0|^11.0
- league/flysystem-aws-s3-v3: ^1.0|^2.0|^3.0
- xantios/mimey: ^2.2
Requires (Dev)
- orchestra/testbench: ^9.0
- pestphp/pest: ^2.34
- pestphp/pest-plugin-laravel: ^2.34
- phpunit/phpunit: ^10.5
README
这是一个 Laravel 包,用于处理和简化在 AWS S3 类似云存储上文件的上传、覆盖、删除和 CDN 清除。
它支持表单上传文件(UploadedFile)或 base64 文件字符串
支持
在当前版本中,它仅支持 Digital Ocean SPACES 云存储。
未来我将添加对新云存储的支持或接受 pull 请求。
配置
您应该通过 composer 安装它
composer require andreinocenti/laravel-file-s3-like
此包使用 Laravel Illuminate\Support\Facades\Storage 门面来处理文件。
因此,您必须配置您想要使用的类似 AWS 的文件系统磁盘。
以下是最优配置
config/filesystem.php
'spaces-disk' => [ 'driver' => 's3', 'key' => env('SPACES_ACCESS_KEY_ID'), 'secret' => env('SPACES_SECRET_ACCESS_KEY'), 'region' => env('SPACES_DEFAULT_REGION'), 'bucket' => env('SPACES_BUCKET'), 'url' => env('SPACES_URL'), 'endpoint' => env('SPACES_ENDPOINT'), 'folder' => env('SPACES_FOLDER'), // This will be the default directory used. It can be empty, if so the default directory will be the bucket root 'cdn_endpoint' => env('SPACES_CDN_ENDPOINT'), // at Digital Ocean Spaces the CDN is auto set when a file is uploaded. So set here the cdn_endpoint (edge) 'use_path_style_endpoint' => env('SPACES_USE_PATH_STYLE_ENDPOINT', false), 'throw' => false, ],
使用方法
您可以使用 FileS3LikeSpaces 门面
use AndreInocenti\LaravelFileS3Like\Facades\FileS3LikeSpaces; FileS3LikeSpaces::disk('spaces-disk') ->directory('images') ->upload($file, 'new-test');
或者您可以使用 FileS3Like 门面,如果这样做,您必须设置您想要使用的 repository()。
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like; FileS3Like::repository('spaces') ->disk('spaces-disk') ->directory('images') ->upload($file, 'new-test');
方法和访问器
FileS3Like 及其存储库(例如:FileS3LikeSpaces)
DiskFile
DiskFile 是一个 DTO 类,在调用上传或保存函数时创建和传递。该类包含返回某些文件数据的访问器。