Laravel-medialibrary: Cloudinary Support

Created on 25 Jul 2018  路  2Comments  路  Source: spatie/laravel-medialibrary

sorry but beginner here..

Cloudinary Support?

tnx. for answering.

Most helpful comment

@mhardaniel123 @mintbridge @bstrahija @uyab @chadjw Cloudinary is fast becoming the media/file storage platform of choice, offering media manipulation capability and serving over CDN with awesome transformations. It will be nice if there's some sort of integration from media-library to Cloudinary

I found this package flysystem-cloudinary. You will need to create a provider:

<?php

namespace App\Providers;

use Enl\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
use Enl\Flysystem\Cloudinary\Converter\TruncateExtensionConverter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Illuminate\Support\ServiceProvider;

class CloudinaryServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    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'],
            ], new TruncateExtensionConverter());

            return new Filesystem(new CloudinaryAdapter($client));
        });
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

in the .env file add:

CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=

and create CloudinaryUrlGenerator class that will extend Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator and implement the methods: getUrl, getTemporaryUrl and getResponsiveImagesDirectoryUrl and do not forget to put the new class in the package configuration file (config/medialibrary.php).

All 2 comments

@mhardaniel123 @mintbridge @bstrahija @uyab @chadjw Cloudinary is fast becoming the media/file storage platform of choice, offering media manipulation capability and serving over CDN with awesome transformations. It will be nice if there's some sort of integration from media-library to Cloudinary

@mhardaniel123 @mintbridge @bstrahija @uyab @chadjw Cloudinary is fast becoming the media/file storage platform of choice, offering media manipulation capability and serving over CDN with awesome transformations. It will be nice if there's some sort of integration from media-library to Cloudinary

I found this package flysystem-cloudinary. You will need to create a provider:

<?php

namespace App\Providers;

use Enl\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
use Enl\Flysystem\Cloudinary\Converter\TruncateExtensionConverter;
use Illuminate\Support\Facades\Storage;
use League\Flysystem\Filesystem;
use Illuminate\Support\ServiceProvider;

class CloudinaryServiceProvider extends ServiceProvider
{
    /**
     * Perform post-registration booting of services.
     *
     * @return void
     */
    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'],
            ], new TruncateExtensionConverter());

            return new Filesystem(new CloudinaryAdapter($client));
        });
    }

    /**
     * Register bindings in the container.
     *
     * @return void
     */
    public function register()
    {
        //
    }
}

in the .env file add:

CLOUDINARY_CLOUD_NAME=
CLOUDINARY_API_KEY=
CLOUDINARY_API_SECRET=

and create CloudinaryUrlGenerator class that will extend Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator and implement the methods: getUrl, getTemporaryUrl and getResponsiveImagesDirectoryUrl and do not forget to put the new class in the package configuration file (config/medialibrary.php).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

intrepidws picture intrepidws  路  3Comments

mokhosh picture mokhosh  路  3Comments

xron89 picture xron89  路  3Comments

ideadx picture ideadx  路  4Comments

swash13 picture swash13  路  3Comments