Reputation: 3321
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.
Upvotes: 14
Views: 54762
Reputation: 666
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 like what awais ahmad mentioned, His solution proved 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.
Upvotes: 1
Reputation: 51
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.
Upvotes: 5
Reputation: 61
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
Upvotes: 6
Reputation: 245
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
Upvotes: 0
Reputation: 487
In laravel ^5.8:
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 );
Upvotes: 4
Reputation: 1088
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).
Upvotes: 47