Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Laravel 基于cloudinary的空间媒体库_Laravel_Cloudinary - Fatal编程技术网

Laravel 基于cloudinary的空间媒体库

Laravel 基于cloudinary的空间媒体库,laravel,cloudinary,Laravel,Cloudinary,我正在尝试集成Spatial media library软件包,以使用cloudinary托管和服务图像 该软件包不支持cloudinary,因此我不得不使用另一个旧软件包:flysystem cloudinary 我还关注了一个关于stackoverflow的讨论,其中有人也与之抗争: 我设法将图像上载到cloudinary,但当我试图检索图像时,出现以下错误: App\Cloudinary\CloudinaryUrlGenerator::getTemporaryUrl()的声明:string

我正在尝试集成Spatial media library软件包,以使用cloudinary托管和服务图像

该软件包不支持cloudinary,因此我不得不使用另一个旧软件包:flysystem cloudinary

我还关注了一个关于stackoverflow的讨论,其中有人也与之抗争:

我设法将图像上载到cloudinary,但当我试图检索图像时,出现以下错误:

App\Cloudinary\CloudinaryUrlGenerator::getTemporaryUrl()的声明:string必须与Spatie\mediabrary\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();
}
}

如果您使用的是
,则可以使用它

由于发布了
v7
getTemporaryUrl
有两个参数:

getTemporaryUrl(DateTimeInterface$expiration,array$options=[]):字符串;
可以将这些参数添加到方法中:

使用DateTimeInterface;
// 
公共函数getTemporaryUrl(DateTimeInterface$expiration,数组$options=[]):字符串
{
返回$this->getUrl();
}
``

读取错误后,您认为可能会出现什么错误?特别是“必须与兼容”部分?hi@ThomasVanderVeen,感谢您的回复-我试图重写函数定义,使其与spatie选项相同:getTemporaryUrl(DateTimeInterface$expiration,array$options):string,但它不起作用并产生相同的错误。请确保导入所有需要的类。如果操作正确,我认为不应该有问题。您确定是因为您的
App\Cloudinary\CloudinaryUrlGenerator
类中的实现而引发错误(只是为了确定)?thx但我使用的是V7。。实际上,我完全按照你写的那样解决了这个问题,但我还有另一个问题。。在cloudinary中覆盖图像不起作用。。。真是糟透了,没有一个包裹装这个。。使用s3和cloudfront/flare会更好吗?我认为cloudinary软件包是有问题的