laravel-medialibrary: The storage path is not part of the public path

Hi,

I get the following error, using latest laravel.

UrlCouldNotBeDetermined in LocalUrlGenerator.php line 19:
The storage path is not part of the public path

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Comments: 17 (4 by maintainers)

Most upvoted comments

I fixed issue by adding a url to the disk like below:

    'disks' => [    

        'media' => [
            'driver'    => 'local',
            'root'      => public_path('media'), 
            'url'       => env('APP_URL') . '/media',
        ],
],

I’m having this issue whereby my public/media is symlinked to storage/media (ln -s ../storage/media public/media from project root) but the realpath() function expands the symlink.

The solution is to remove the realpath() from the return in LocalUrlGenerator::getStoragePath().

@WolfieZero that has fixed the problem thanks, but should it be added to the repo?

I’m facing this exact same problem, it looks like I’ve done everything correctly, but I still get the same exception. What for me seems to be a problem is this method:

// LocalUrlGenerator.php
/*
 * Get the path where the whole medialibrary is stored.
 */
protected function getStoragePath() : string
{
    $diskRootPath = $this->config->get('filesystems.disks.'.$this->media->disk.'.root');

    return realpath($diskRootPath);
}

The first line returns the correct path /home/vagrant/website/public/storage/media. But the call to realpath() turns the path into /home/vagrant/website/storage/app/public/media.

What am I doing wrong?

Be careful and understand what disk you are using. Local does not mean to be public. Public is for real public resources. (According to the default disk from a fresh Laravel installation)

    'local' => [
        'driver' => 'local',
        'root' => storage_path('app'),
    ],

    'public' => [
        'driver' => 'local',
        'root' => storage_path('app/public'),
        'url' => env('APP_URL').'/storage',
        'visibility' => 'public',
    ],