flysystem-aliyun-oss icon indicating copy to clipboard operation
flysystem-aliyun-oss copied to clipboard

This driver does not support retrieving URLs.

Open cangsongbayu opened this issue 5 years ago • 1 comments

我使用 flysystem-aliyun-oss 进行文件上传,文件可以正常上传到阿里云 OSS 服务器

但是生成文件 url 路径时就会报错 :This driver does not support retrieving URLs.

源码调试发现 Laravel 7 代码如下 :

// Illuminate\Filesystem\FilesystemAdapter;
 
/**
     * Get the URL for the file at the given path.
     *
     * @param  string  $path
     * @return string
     *
     * @throws \RuntimeException
     */
    public function url($path)
    {
        $adapter = $this->driver->getAdapter();

        if ($adapter instanceof CachedAdapter) {
            $adapter = $adapter->getAdapter();
        }

//        var_dump($path); die;

//        var_dump($adapter); die;

        var_dump(method_exists($adapter, 'getUrl')); die;

        if (method_exists($adapter, 'getUrl')) {
            return $adapter->getUrl($path);
        } elseif (method_exists($this->driver, 'getUrl')) {
            return $this->driver->getUrl($path);
        } elseif ($adapter instanceof AwsS3Adapter) {
            return $this->getAwsUrl($adapter, $path);
        } elseif ($adapter instanceof Ftp) {
            return $this->getFtpUrl($path);
        } elseif ($adapter instanceof LocalAdapter) {
            return $this->getLocalUrl($path);
        } else {
            throw new RuntimeException('This driver does not support retrieving URLs.');
        }
    }

上面代码检测 $adapter 是否有 getUrl 方法,但 flysystem-aliyun-oss 库中 AliyunOssAdapter 类并没有 getUrl 方法,导致上面逻辑总是走到 throw new RuntimeException('This driver does not support retrieving URLs.');

不知道是我写的问题还是 flysystem-aliyun-oss 库本身 Bug,还是我写的有问题

cangsongbayu avatar Aug 21 '20 16:08 cangsongbayu

参见: https://github.com/apollopy/flysystem-aliyun-oss/issues/7

apollopy avatar Aug 22 '20 03:08 apollopy