spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.75k stars 1.07k forks source link

Cloudinary Support #1185

Closed mhardaniel closed 6 years ago

mhardaniel commented 6 years ago

sorry but beginner here..

Cloudinary Support?

tnx. for answering.

nwaughachukwuma commented 5 years ago

@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

victorhsanjos commented 5 years ago

@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).

xfkrahmad commented 1 year ago

sorry guys. if i using laravel 9, will it work?

uyab commented 1 year ago

@xfkrahmad you should ask that to https://github.com/enl/flysystem-cloudinary