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

Filesystem URL creation for Local driver has a hardcoded path prefix #13364

Closed
briedis opened this issue Apr 28, 2016 · 8 comments
Closed

Filesystem URL creation for Local driver has a hardcoded path prefix #13364

briedis opened this issue Apr 28, 2016 · 8 comments

Comments

@briedis
Copy link

briedis commented Apr 28, 2016

Fetching URLs for local filesystem is conflicting with filesystem configuration option. I've specified where I want my files to be stored (public directory)

'root' => public_path('my-storage-directory'),

Code assuming that we always store in storage directory, no options to override it:

} elseif ($adapter instanceof LocalAdapter) {
            return '/storage/'.$path;
} else {

(Source)

Perhaps it would be better if we could specify the prefix (not the full path) in config array, like, in a publicRoot field, or something like that.

@j3j5
Copy link
Contributor

j3j5 commented Sep 2, 2016

This hardcoded path on the FileSystemAdapter actually returns a wrong value for the default config (default is storage_path('app') and Storage::url() would omit the app).

Now in 5.3 there's a public driver and the code is even uglier (looking for public and replacing the occurence) source.

I am not sure what the behaviour should be for url() but right now it just returns wrong paths for the local driver with the default settings.

@thomassjogren
Copy link

Just ran into this problem myself testing generation of a file. I thought it would adhere to the configuration of the used disk but as you say, the prefix is hardcoded as you say.

@j3j5
Copy link
Contributor

j3j5 commented Sep 9, 2016

ATM I am using the much less convenient config('filesystems.disks.local.root') . DIRECTORY_SEPARATOR . $filename.

@briedis
Copy link
Author

briedis commented Sep 11, 2016

@j3j5 I'm doing similiary. Feels like a hack..

protected function getUrl()
    {
        /** @var Filesystem|FilesystemAdapter $storage*/
        $storage= \app('storage.images');

        $adapter = $storage->getAdapter();

        if ($adapter instanceof AwsS3Adapter) {
            return $storage->url($this->getFilePathname());
        }

        if ($adapter instanceof Local) {
            return url('uploads/images/' . $this->getFilePathname());
        }

        throw new \Exception('Unknown driver, can`t generate URL');
    }

@thomassjogren
Copy link

The LocalAdapter also have a getPathPrefix() method that returns the root set in the config, so I guess that should be used in the FilesystemAdapter.php.

@masonfox
Copy link

I also had this issue 👍

tomasfejfar added a commit to tomasfejfar/framework that referenced this issue Oct 20, 2016
tomasfejfar added a commit to tomasfejfar/framework that referenced this issue Oct 20, 2016
tomasfejfar added a commit to tomasfejfar/framework that referenced this issue Oct 20, 2016
@stpangia
Copy link

stpangia commented Nov 1, 2016

this works for me:

Storage::disk('local')->getDriver()->getAdapter()->getPathPrefix()

@themsaid
Copy link
Member

This should be fixed here: #16281

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

6 participants