overtrue / laravel-filesystem-cos

Tencent Cloud COS storage for Laravel based on overtrue/flysystem-cos.
MIT License
89 stars 8 forks source link

This driver does not support creating temporary URLs. #18

Closed chaiyanlin closed 2 months ago

chaiyanlin commented 2 months ago

Laravel Framework 10.48.22

在框架FilesystemAdapter中方法temporaryUrl实际是调用adaptergetTemporaryUrl,具体代码如下:

    /**
     * Get a temporary URL for the file at the given path.
     *
     * @param  string  $path
     * @param  \DateTimeInterface  $expiration
     * @param  array  $options
     * @return string
     *
     * @throws \RuntimeException
     */
    public function temporaryUrl($path, $expiration, array $options = [])
    {
        if (method_exists($this->adapter, 'getTemporaryUrl')) {
            return $this->adapter->getTemporaryUrl($path, $expiration, $options);
        }

        if ($this->temporaryUrlCallback) {
            return $this->temporaryUrlCallback->bindTo($this, static::class)(
                $path, $expiration, $options
            );
        }

        throw new RuntimeException('This driver does not support creating temporary URLs.');
    }

但现在CosAdapter中不存在getTemporaryUrl,导致Storage::temporaryUrl调用失败,提示"This driver does not support creating temporary URLs."

overtrue commented 2 months ago

感谢反馈,已更新,麻烦更新 overtrue/flysystem-cos 至 5.1.11

composer update overtrue/flysystem-cos
chaiyanlin commented 2 months ago

感谢反馈,已更新,麻烦更新 overtrue/flysystem-cos 至 5.1.11

composer update overtrue/flysystem-cos

下面的代码似乎有问题,$expiresAt并没有初始化,所以当执行$expiresAt instanceof \DateTimeInterface会报错,似乎应该把$expiresAt替换成$expiration?

public function getTemporaryUrl(string $path, $expiration)
    {
        if ($expiresAt instanceof \DateTimeInterface) {
            $expiration = $expiresAt->getTimestamp();
        }

        try {
            return $this->getSignedUrl($path, $expiration);
        } catch (\Throwable $exception) {
            throw UnableToGenerateTemporaryUrl::dueToError($path, $exception);
        }
    }