andreinocenti / laravel-file-s3-like
A package to upload, update, delete, purge a S3 like storage via Laravel
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
This is a Laravel package that handles and make easy the upload, overwrite, delete, cdn purge of files and directories on AWS S3 like cloud storages.
It supports a form uploaded file (UploadedFile) or a base64 file string
Support
At the actual version it support only Digital Ocean SPACES cloud storage.
In the future I will add new cloud storages support or accept pull requests.
Configuration
You should install it via composer:
composer require andreinocenti/laravel-file-s3-like
This package use the Laravel Illuminate\Support\Facades\Storage facade to handle the files.
So you must config the filesystem AWS like disk that you want to use.
Below the optimal config to be used
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, ],
Usage
You can use the FileS3LikeSpaces facade
use AndreInocenti\LaravelFileS3Like\Facades\FileS3LikeSpaces; FileS3LikeSpaces::disk('spaces-disk') ->directory('images') ->upload($file, 'new-test');
Or you can use the FileS3Like Facade, if you do you must set the repository() you want to use.
use AndreInocenti\LaravelFileS3Like\Facades\FileS3Like; FileS3Like::repository('spaces') ->disk('spaces-disk') ->directory('images') ->upload($file, 'new-test');
Methods / Accessors
FileS3Like and its repositories (Eg: FileS3LikeSpaces)
DiskFile
DiskFile is a DTO class that is created and delivered when the functions upload or save are called. The class contain accessors that returns some file data.