Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

This driver does not support retrieving URLs. #10

Open
cangsongbayu opened this issue Aug 21, 2020 · 1 comment
Open

This driver does not support retrieving URLs. #10

cangsongbayu opened this issue Aug 21, 2020 · 1 comment

Comments

@cangsongbayu
Copy link

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

@apollopy
Copy link
Owner

apollopy commented Aug 22, 2020

参见: #7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants