carlosocarvalho/flysystem-cloudinary

Flysystem 的 Cloudinary 适配器

v2.0.4 2023-04-25 19:39 UTC

README

The PHP League Flysystem v3 的 Cloudinary 适配器

Codacy Badge Author Latest Stable Version Total Downloads License Suggesters Dependents composer.lock Monthly Downloads

安装

  composer require carlosocarvalho/flysystem-cloudinary

配置

您可以通过两种方式配置此软件包。

使用 CLOUDINARY_URL

您可以使用环境变量 CLOUDINARY_URL 来配置库。使用 CLOUDINARY_URL 时,您可以直接访问底层 Cloudinary SDK,无需实例化适配器或显式实例化 Cloudinary SDK。

您可以在他们的文档中了解更多信息:https://cloudinary.com/documentation/php_integration#setting_the_cloudinary_url_environment_variable

use CarlosOCarvalho\Flysystem\Cloudinary\CloudinaryAdapter;
use League\Flysystem\Filesystem;

$adapter = new CloudinaryAdapter();
$filesystem = new Filesystem( $adapter );

手动配置

use CarlosOCarvalho\Flysystem\Cloudinary\CloudinaryAdapter;
use League\Flysystem\Filesystem;

$config = [
    'api_key' => ':key',
    'api_secret' => ':secret',
    'cloud_name' => ':name',
];

$adapter = new CloudinaryAdapter($config);
$filesystem = new Filesystem( $adapter );

示例

使用 Filesystem api 列出内容和其他操作

#Options use file type resource





$filesystem->listContents()

在容器中添加资源类型列表 imagevideoraw

CloudinaryAdapter::$resourceType = \Cloudinary\Asset\AssetType::IMAGE;
$filesystem->listContents()

在 Laravel 中使用

要在 Laravel 中使用,必须注册驱动。请在 Laravel 文档中学习如何注册自定义文件系统

    use Illuminate\Filesystem\FilesystemAdapter;
    use Illuminate\Support\Facades\Storage;
    use League\Flysystem\Filesystem;
    use CarlosOCarvalho\Flysystem\Cloudinary\CloudinaryAdapter;

    ...

    Storage::extend('cloudinary', function ($app, $config) {
        if(!empty(env('CLOUDINARY_URL'))){
            $adapter = new CloudinaryAdapter();
        }else{
            $adapter = new CloudinaryAdapter($config);
        }

        return new FilesystemAdapter(
            new Filesystem($adapter, $config),
            $adapter,
            $config
        );
    });

访问此仓库