12
votes

I am using laravel 5.4. I upload some document file in storage/app/public/documents folder like

$request->paper_file->store('documents');

and my file uploaded successfully.

in file system default storage is public and public conf is like

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

but when i hit /storage/documents/hQqlgifnVVH8bmrRPVdZ9aFGbhLmcc7g7bHZSX4u.pdf it says not found 404. How to solve this issue.

6
Do you see the file in the filesystem? The docs show it being used like $request->file('paper')->store('documents') but I'm not sure what your paper_file bit is.ceejayoz
my file uploaded successfully. the file name is paper_file.Iftakharul Alam
Where is hQqlgifnVVH8bmrRPVdZ9aFGbhLmcc7g7bHZSX4u coming from, then?ceejayoz
This is laravel generated dynamic file name. laracasts.com/series/whats-new-in-laravel-5-3/episodes/12Iftakharul Alam
could u please add your method that handles the upload processAmr Aly

6 Answers

39
votes

By default Laravel puts files in the storage/app/public directory, which is not accessible from the outside web. So you have to create a symbolic link between that directory and your public one:

storage/app/public -> public/storage

You can do that by executing the php artisan storage:link command (docs).

4
votes

In laravel ^5.8:

  • Make sure you run the command php artisan storage:link to link storage/app/public with public/storage.

now:

// this return some like 'public/documents/file.ext'
$path = $request->paper_file->store('public/documents');

// this return some like 'storage/documents/file.ext'
$publicPath = \Storage::url( $path) );

// this return some like '< APP_URL env variable >/storage/documents/file.ext'
$url = asset( $publicPath );

4
votes

This problem happen to me after moving project to different folder. If you already have storage link generated, try to delete public/storage folder and run again:

php artisan storage:link
3
votes

When you upload an image with Laravel's storage function it is stored in a storage folder. For example: storage/app/public/avatars/file1.png

But when you want to access it via URL, you should access it like this:

storage/avatars/file1.png

It worked for me, using Laravel 7.x.

1
votes

If you are coming from laravel 8.x and have indeed ran the command php artisan storage:link(to create a symbolic link ), but your code is not working i.e the file you are trying to load is not displaying, then you are like me.

Just awais ahmad mentioned, This solution porved helpful with my laravel 8x project. I have not added the "storage" path name from my blade file with the asset helper function so my image path was not outputing anything but when I typed the 'storage' path name like so asset('storage/uploads/pic1.png) my code worked!

Guess this might help someone.

0
votes

After running php artisan storage:link it creates a symbolic link in the public folder and you can retrieve record like so <img src='{{ asset("public/$advert6") }}' class="img-responsive">. You should include the public directory