PHP code example of wearemodus / flysystem-cloudinary

1. Go to this page and download the library: Download wearemodus/flysystem-cloudinary library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

wearemodus / flysystem-cloudinary example snippets


   'disks' => [
        ...
   
        'cloudinary' => [
            'driver'     => 'cloudinary',
            'cloud_name' => env('CLOUDINARY_CLOUD_NAME'),
            'api_key'    => env('CLOUDINARY_API_KEY'),
            'api_secret' => env('CLOUDINARY_API_SECRET'),
        ],
   ]
   

    use WeAreModus\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
    use WeAreModus\Flysystem\Cloudinary\CloudinaryAdapter;
    use WeAreModus\Flysystem\Cloudinary\Converter\TruncateExtensionConverter;
    use Illuminate\Support\Facades\Storage;
    use Illuminate\Support\ServiceProvider;
    use League\Flysystem\Filesystem;
   
   ...
   
   public function boot() 
   {
        Storage::extend('cloudinary', function ($app, $config) {
        $client = new CloudinaryClient(
                [
                    'cloud_name' => $config['cloud_name'],
                    'api_key'    => $config['api_key'],
                    'api_secret' => $config['api_secret'],
                    'overwrite'  => $config['overwrite'] ?? true,
                ], // Cloudinary API options
                [
                    'resource_type'          => 'auto',
                    'eager'                  => [
                        ['fetch_format' => 'mp4', 'format' => '', 'video_codec' => 'h264', 'quality' => '70'], // f_mp4,vc_h264,q_70
                        ['fetch_format' => 'png', 'format' => '', 'quality' => '70'], // f_png,q_70
                    ],
                    'eager_async'            => 'true',
                    'eager_notification_url' => 'https://mysite.test/webhook/eager',
                    'notification_url'       => 'https://mysite.test/webhook/upload',
                    ...
                ], // Upload options
                new TruncateExtensionConverter()
           );
            
            return new Filesystem(new CloudinaryAdapter($client));
        });
   }
   

    $this->addMediaCollection('videos')->useDisk('cloudinary'); // Use Cloudinary as disk for the entire collection
    // OR
    $model->addMedia($mediaPath)
          ->toMediaCollection('videos', 'cloudinary'); // USe Cloudinary as disk for this media only
   
 php

use WeAreModus\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
use WeAreModus\Flysystem\Cloudinary\CloudinaryAdapter;
use League\Flysystem\Filesystem;

> true, // set this to true if you want to overwrite existing files using $filesystem->write();
]);

$adapter = new CloudinaryAdapter($client);
// This option disables assert that file is absent before calling `write`.
// It is necessary if you want to overwrite files on `write` as Cloudinary does it by default.
$filesystem = new Filesystem($adapter, ['disable_asserts' => true]);