Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

Method getUrl is not working #3

Closed
guidosegni opened this issue Oct 27, 2016 · 5 comments
Closed

Method getUrl is not working #3

guidosegni opened this issue Oct 27, 2016 · 5 comments
Labels

Comments

@guidosegni
Copy link

Just stumbled upon this error:

I can correctly upload files (i found it in the firebase storage console) but when invoking the getUrl method here it is what I see:

BadMethodCallException in PluggableTrait.php line 85:
Call to undefined method League\Flysystem\Filesystem::getUrl

This is the simple code I'm using in a controller

$disk = Storage::disk('gcs');
$url = $disk->getUrl('media/test.png');

it seems the $disk doesn't have the getUrl Method.
I made a test in the GoogleCloudStorageServiceProvider.php file and here:

$adapter = new GoogleStorageAdapter($storageClient, $bucket, $pathPrefix, $storageApiUri);          
return new Filesystem($adapter);

the $adapter has the getUrl method, but the constructor new Filesystem($adapter) returns an object without that method.

Am I missing something?

@thebrubaker
Copy link

I'm having the same problem. +1

BadMethodCallException in PluggableTrait.php line 85: Call to undefined method League\Flysystem\Filesystem::getUrl

@beesperester
Copy link

The method is obfuscated but you can access it like this:
$url = Storage::disk('gcs')->getDriver()->getAdapter()->getUrl('some/file.txt');

@matthewgoslett
Copy link
Contributor

I haven't had a chance to look into this yet.

What magic is Laravel doing here (https://laravel.com/docs/5.3/filesystem#file-urls) to check if the adapter is able to provide a url?

@mgallegos
Copy link

I have the same problem, but I'm using Laravel 5.2.

@matthewgoslett
Copy link
Contributor

This seems to be a documentation issue.

Laravel's storage facade resolves to an instance of a FilesystemAdapter.
This class has a method called url which does the following:

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

        if (method_exists($adapter, 'getUrl')) {
            return $adapter->getUrl($path);
        } elseif ($adapter instanceof AwsS3Adapter) {
            $path = $adapter->getPathPrefix().$path;

            return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);
        } elseif ($adapter instanceof LocalAdapter) {
            $path = '/storage/'.$path;

            return Str::contains($path, '/storage/public') ? Str::replaceFirst('/public', '', $path) : $path;
        } else {
            throw new RuntimeException('This driver does not support retrieving URLs.');
        }
    }

It checks if the adapter, in this case, GoogleStorageAdapter, has a method called getUrl, which it does.

Can you please try Storage::disk('gcs')->url('path/to/file.txt')?

This is working for me.

\Storage::disk('index_feeds')->url('path/to/file.txt');
=> "http://storage.googleapis.com/my-bucket-name/path/to/file.txt"

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

No branches or pull requests

5 participants