Skip to content

This driver does not support retrieving URLs. #10

@cangsongbayu

Description

@cangsongbayu

我使用 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,还是我写的有问题

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions