【问题标题】:How get cloudinary file url/other properties by public_id?如何通过 public_id 获取 cloudinary 文件 url/其他属性?
【发布时间】:2021-09-27 17:12:13
【问题描述】:

在 cloudinary 下保存图像(使用 cloudinary-laravel 1.0)我将 public_id 保存在我的数据库中 我想通过 public_id 获取这个文件的 url(http 或 https)、大小、尺寸

读到这里

/**
 * You can also retrieve a url if you have a public id
 */

$url = Storage::disk('cloudinary')->url($publicId);

https://github.com/cloudinary-labs/cloudinary-laravel

我得到了错误:

Disk [CLOUDINARY] does not have a configured driver.

  
  

但我使用 storeOnCloudinaryAs 方法将图像保存到 cloudinary,并且在我的 .env 中

CLOUDINARY_URL=cloudinary://NNNNNNNNNNNN:AErjB_-XXXXXXXXX
CLOUDINARY_UPLOAD_PRESET=ml_default

和默认文件 config/cloudinary.php 我的 config/filesystems.php 没有任何云参数,这可能是我的错误的原因吗?

在这种情况下使用 Storage:: 对我来说也很奇怪,但我没有 查找如何通过 public_id 获取文件 url/其他属性?

编辑 1: 我加了一行

...
CloudinaryLabs\CloudinaryLaravel\CloudinaryServiceProvider::class,
...

在 ny config/app.php 的“providers”块中并清除缓存。 但还是得到了

"Disk [CLOUDINARY] does not have a configured driver."

错误。

将更改应用到 .env 并清除缓存我尝试调试在文件 vendor/laravel/framework/src/Illuminate/Filesystem/FilesystemManager.php 中触发的行错误为:

protected function resolve($name)
{
    $config = $this->getConfig($name);

    \Log::info(  varDump($name, ' -1 $name resolve::') ); // IT HAS ‘CLOUDINARY’ value
    if (empty($config['driver'])) {
        throw new InvalidArgumentException("Disk [{$name}] does not have a configured driver.");
    }

但是这个文件中 $config 的来源是什么?

配置/文件系统.php ?在这个文件中,我没有任何 CLOUDINARY 块。也许我需要添加它?但是是哪种格式呢?

提前致谢!

【问题讨论】:

  • 请查看Edited 1 block

标签: laravel cloudinary


【解决方案1】:

将驱动设置为小写

$cloudinaryUrl = Storage::disk(strtolower($imagesUploadSource))

修正了这个错误。

【讨论】:

    猜你喜欢
    • 2017-02-24
    • 2021-06-19
    • 2017-04-20
    • 2021-11-17
    • 2015-10-20
    • 1970-01-01
    • 1970-01-01
    • 2021-12-21
    • 1970-01-01
    相关资源
    最近更新 更多