vormkracht10 / flysystem-uploadcare
Flysystem driver for Uploadcare for Laravel.
Fund package maintenance!
vormkracht10
Installs: 19 095
Dependents: 0
Suggesters: 0
Security: 0
Stars: 16
Watchers: 4
Forks: 2
Open Issues: 1
Requires
- php: ^8.1
- illuminate/support: ^9.0|^10.0|^11.0
- league/flysystem: ^3.0
- uploadcare/uploadcare-php: ^4.1
Requires (Dev)
- laravel/pint: ^1.0
- nunomaduro/collision: ^6.1
- nunomaduro/larastan: ^2.0.1
- orchestra/testbench: ^8.0
- pestphp/pest: ^1.21
- pestphp/pest-plugin-laravel: ^1.1
- phpstan/extension-installer: ^1.1
- phpstan/phpstan-deprecation-rules: ^1.0
- phpstan/phpstan-phpunit: ^1.0
- phpunit/phpunit: ^9.6
README
Flysystem adapter for Uploadcare with support for Laravel v9+.
Installation
You can install the package via composer:
composer require vormkracht10/flysystem-uploadcare
Add the following config to the disk
array in config/filesystems.php
[ 'uploadcare' => [ 'driver' => 'uploadcare', 'public' => env('UPLOADCARE_PUBLIC_KEY'), 'secret' => env('UPLOADCARE_SECRET_KEY'), 'cdn' => env('UPLOADCARE_CDN') // Default https://ucarecdn.com ] ]
Then set the FILESYSTEM_DISK
to uploadcare
in your .env
FILESYSTEM_DISK=uploadcare
Examples
Please note: Since adding files to uploadcare always returns a unique id that will be used to retrieve files you might wanna use the *GetUuid()
function(s) for writing files.
$uuid = Storage::disk('uploadcare')->putGetUuid('example.txt', 'My notes.'); $uuid = Storage::disk('uploadcare')->putFileGetUuid('files', new File('/var/www/uploadcare-app/routes/newcontent.txt')); $uuid = Storage::disk('uploadcare')->putFileAsGetUuid('files', new File('/var/www/uploadcare-app/routes/newcontent.txt'), 'my-awesome-name.txt');
Get the content of a file
$contents = Storage::disk('uploadcare')->get('<uuid>');
Deleting a file:
Storage::disk('uploadcare')->delete('<uuid>');
Getting the mimetype of a file
$mimeType = Storage::disk('uploadcare')->mimeType('<uuid>');
Get the filesize of a file
$bytes = Storage::disk('uploadcare')->filesize('<uuid>');
Get the original filename
$info = Storage::disk('uploadcare')->fileInfo($result[0]); $filename = $info->extraMetadata()['originalFilename'];
Get a list of files
Directories in uploadcare are stored with an "~"-sign at the end of a uuid. Getting files from a directory could be retreived as follow:
$files = Storage::disk('uploadcare')->files('0123a456-a0bc-0a1b-0ab1-0a1234a5b6c7~'); foreach ($files as $uuid) { echo 'https://ucarecdn.com/' . $uuid .'<br />'; }
Working with images? See github.com/vormkracht10/php-uploadcare-transformations
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.