• Reading time ~ 1 min
  • 31.05.2023

The Uploadcare PHP package is an adapter for Flysystem that makes it easy to use the Uploadcare API in Laravel 10+ apps:

$uuid = Storage::disk('uploadcare')
    ->putGetUuid('example.txt', 'My notes.');

$uuid = Storage::disk('uploadcare')
    ->putFileGetUuid('files', new File('/path/to/newcontent.txt'));

$uuid = Storage::disk('uploadcare')
    ->putFileAsGetUuid(
        'files',
        new File('/path/to/newcontent.txt'),
        'my-awesome-name.txt'
    );

To retrieve and manage files from Uploadcare using Flysystem, you provide the UUID of the resource you want to retrieve:

// Get the content of a file
Storage::disk('uploadcare')->get('<uuid>');

// Delete a file
Storage::disk('uploadcare')->delete('<uuid>');

If you're working with images, the package author has a PHP Uploadcare transformations package that provides image manipulation tools:

use Vormkracht10\UploadcareTransformations\UploadcareTransformation;

$uuid = '12a3456b-c789-1234-1de2-3cfa83096e25';
$cdnUrl = 'https://example.com/cdn/';

$transformation = (new UploadcareTransformation($uuid, $cdnUrl));

$url = $transformation->crop(width: 320, height: '50p', offsetX: 'center')->setFill(color: 'ffffff');

echo $url;

You can install this package via composer with the following command:

composer require vormkracht10/flysystem-uploadcare

The source code contains complete installation instructions and examples of how you can use the Flysystem API with Uploadcare.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297