【发布时间】:2020-06-14 02:50:14
【问题描述】:
我正在尝试集成 spatie 媒体库包以使用 cloudinary 来托管和提供图像..
该软件包不支持 cloudinary,所以我不得不使用另一个旧软件包:flysystem-cloudinary
我还关注了关于 stackoverflow 的讨论,其中有人也与之抗争:spatie-cloudinary
我设法将图像上传到 cloudinary,但是当我尝试检索它时,出现以下错误:
App\Cloudinary\CloudinaryUrlGenerator::getTemporaryUrl()的声明:string必须兼容Spatie\MediaLibrary\UrlGenerator\UrlGenerator::getTemporaryUrl(DateTimeInterface $expiration, array $options = Array): string
这是我的 CloudinaryUrlGenerator:
<?php
namespace App\Cloudinary;
use Spatie\MediaLibrary\UrlGenerator\BaseUrlGenerator;
class CloudinaryUrlGenerator extends BaseUrlGenerator
{
const HOST = 'https://res.cloudinary.com/';
/**
* Get the url for a media item.
*
* @return string
*/
public function getUrl(): string
{
$cloudBaseUrl = self::HOST . config('filesystems.disks.cloudinary.cloud_name') . '/';
$options = [
'q_auto',
];
$filePathIncludingFilenameAndExtension = '/' . $this->pathGenerator->getPath($this->media) . $this->media->file_name;
return $cloudBaseUrl . implode(',', $options) . $filePathIncludingFilenameAndExtension;
}
/**
* Get the temp url for a media item.
*
* @return string
*/
public function getTemporaryUrl(): string
{
return $this->getUrl();
}
/**
* Get the responsive images directory url for a media item.
*
* @return string
*/
public function getResponsiveImagesDirectoryUrl(): string
{
return $this->getUrl();
}
}
我尝试使用函数定义,但没有解决。
【问题讨论】:
-
您认为通过阅读错误可能有什么问题?尤其是“必须兼容”部分?
-
嗨@ThomasVanderVeen,感谢您的回复-我尝试将函数定义重写为与 spatie 选项相同:getTemporaryUrl(DateTimeInterface $expiration, array $options): string 但它不起作用并产生了同样的错误。
-
确保导入所有需要的类。如果做得正确,我认为应该没有问题。您确定错误是由于 your
App\Cloudinary\CloudinaryUrlGenerator类中的实现而引发的(只是为了确定)?
标签: laravel cloudinary