rovac
rovac

Reputation: 2103

Can't access files in linked storage folder in laravel by url

I have an app that saves pdfs to the Laravel storage folder that must then be made public.

I linked the /storage folder in laravel's root to public as per laravel instructions by using: php artisan storage:link

I'm having a confusing issue where I can't figure out how to access the files in that storage folder via URL.

When it comes to path to those files, they are now located in storage here:

/storage/app/public/

And the linked path to that same folder is

/public/storage/

if I put a test file in /public/ i can access it by going to localhost:3000/file.pdf

However if I try to put a file in /public/storage/, I get a 404 when I go to localhost:3000/storage/file.pdf and I can't figure out why!

The files are being correctly linked, as I can find them both in /public/storage and in /storage/app/public folders, the content of those folders match.

When I run dd( public_path() ); I get: "/home/vagrant/code/project/public"

When I run dd( storage_path() ); I get: "/home/vagrant/code/project/storage"

I have the following in my filesystems.php file:

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

Which seems to mean that the files being saved to storage should be saved to /storage/app/public which is true, and that the url should be localhost:3000/storage which seems not to be working! What am I missing?

Upvotes: 0

Views: 1287

Answers (1)

Rudolf
Rudolf

Reputation: 48

Are you sure your laravel project is running on localhost:3000 and not on localhost:80?

I am wondering because usually localhost:3000 is used by some sort of node.js (vue/nuxt.js) application. If so your laravel backend part should be accessible via api or on localhost/storage/file.pdf (if file is directly under app/public folder).

Let me know if it helped.

Upvotes: 0

Related Questions