enl/flysystem-cloudinary

Flysystem 的 Cloudinary 适配器。

1.3.0 2020-08-20 11:45 UTC

This package is auto-updated.

Last update: 2024-09-20 20:51:51 UTC


README

Build Status Software License Coverage Status

这是一个为 Flysystem 适配器,用于 Cloudinary API

安装

composer require enl/flysystem-cloudinary '~1.0'

或者只需将以下字符串添加到你的 composer.json 文件的 require 部分

{
    "require": {
        "enl/flysystem-cloudinary": "~1.0"
    }
}

引导

<?php
use Enl\Flysystem\Cloudinary\ApiFacade as CloudinaryClient;
use Enl\Flysystem\Cloudinary\CloudinaryAdapter;
use League\Flysystem\Filesystem;

include __DIR__ . '/vendor/autoload.php';

$client = new CloudinaryClient([
    'cloud_name' => 'your-cloudname-here',
    'api_key' => 'api-key',
    'api_secret' => 'You-know-what-to-do',
    'overwrite' => 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]);

Cloudinary 功能

请注意 Cloudinary 的三个可能的问题

  • 它会自动为 public_id 添加文件扩展名。在 Flysystem 中,cloudinary 的 public_id 被视为文件名。但如果你设置 public_id 为 'test.jpg',Cloudinary 会将文件保存为 'test.jpg.jpg'。为了解决这个问题,你可以使用 PathConverterInterface
  • 它不支持通过 API 创建文件夹
  • 如果你想使用文件夹保存文件,你应该设置 public_id 为 'test/test.jpg',并在 Cloudinary 控制台中允许自动创建文件夹。

好消息!

该库支持 Cloudinary 变换