Not Showing user avatar - laravel

HTML tag
<img src="storage/app/avatars/23_avatar1548246815.bmp" alt="">
File already exist on this path. But not showing.
And I used also this php artisan storage:link, but not working.
Error is Server Error 403 Forbidden.

According to laravel documentation.
The Public Disk
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. This convention will keep your publicly accessible files in one directory that can be easily shared across deployments when using zero down-time deployment systems like Envoyer.
To create the symbolic link, you may use the storage:link Artisan command:
php artisan storage:link
Of course, once a file has been stored and the symbolic link has been created, you can create a URL to the files using the asset helper:
echo asset('storage/file.txt');
thing I would do is definitely use this method
<img src="{{asset('assets/images/image.png')}}">
to link to your asset files.
Shouldnt the storage/app/avatars be storage/app/pubic/avatars ?

If you say that the file exists on that path, it points that the problem is with file permissions. Change the /project/storage permissions to 777, delete the public/storage folder, and run php artisan storage:link, then try one more time. If no, try to give 777 permissions to public folder

Related

Laravel files not storing in storage directory

I'm storing files in Laravel api. Files are mostly images. The images are storing at public/storage/claim-images but not in storage/app/public/claim-images. Isn't images supposed to stored in both directory ? Here is how I'm storing the files
return Storage::disk('public')->put('claim-images', $request->file('claim-image'));
Note that I alreday run the php artisan storage:link
Laravel version - 7.30
Read your filesystem.php. You are using the public disk in your code, this means that the path will be public_path() as seen in the configuration.
What you are looking for is to use the 'local' disk, which should default to storage_path('app'). For all defaults, check the source on Github here.
php artisan storage:link is creating a Symlink IN the public folder TO de storage folder. So this is not working out for you since you are storing files directly in the public folder instead of the storage folder. The correct end result should be that all files reside in the storage folder, while the symlink in the public folder refers to that directory.
See for more info https://laravel.com/docs/8.x/filesystem#the-public-disk

Cannot display image in vue.js

I'm saving image in following path :
storage\app\public\img\user_image
and saving image url like this in database:
/img/user_image/285070719.png
trying to display image like this:
<img :src="'../app/public'+profile.image">
but the image does not display, Any solution to resolve this issue is highly appreciated.
Have you create a storage link? php artisan storage:link https://laravel.com/docs/8.x/filesystem#the-public-disk
Then you should be able to use the uri like /storgae/img/user_image/285070719.png
Make sure that you created the symlink from public/storage to storage/app/public with php artisan storage:link, after that make sure that the generated URL is correct.
The following URL should be generated:
http://localhost:8000/storage/img/user_image/285070719.png
Something like the following should work for you:
<img :src="'/storage'+profile.image">
From the docs:
The public disk is intended for files that are going to be publicly accessible. By default, the public disk uses the local driver and stores these files in storage/app/public. To make them accessible from the web, you should create a symbolic link from public/storage to storage/app/public. To create the symbolic link, you may use the storage:link Artisan command: php artisan storage:link

laravel symlinks on a window machine

Using a windows server, I have a laravel installation.
I have a storage folder that I have created on 'root/storage'
When I save images from the website, the images are stored in this folder.
I use this to save the files:
Storage::disk('local')->put('course_badges/'.$pre_string . $request->file('badge')->getClientOriginalName(), File::get($request->file('badge')));
When I try to reference the file like so 'https://app.com/storage/file_name.jpg', laravel gives me a 'Sorry, the page you are looking for could not be found.' error.
However is I copy the files to '/public/storage/'
The image is then referenced correctly.
I have run the: php artisan symlink function.
I have tried to run ln -s ../storage/ command in powershell, but windows tells me that ln is not recognized.
What I am trying to achieve is to have my files saved in the root/storage folder (and sub folders)
and to reference them using https:app.nam/storage/file
I had simmilar issue
as u mentioned file is stored in root/storage means problem with symlink between root/storage to public/storage to fix this
remove storage folder from public dir
Note:- keep backup first
then run php artisan storage:link
it should work

File storage link in Laravel

I use:
php artisan storage:link
After that i can access my file in public/storage
But when I add file like this:
request()->image->store('public/storage/foto');
or
request()->image->store('storage/foto');
or
request()->image->store('foto');
That put my file in storage/uploads directory and I don't have access to this files from browser. what did I do wrong? Maybe I skip some important settings?
You need to ensure that the file is stored on your public disk in order for it to be accessible from a browser. You can specify the disk in the store method by adding it as a second parameter, e.g. request()->image->store('foto', 'public');.
Try this :
$request->file('image')->storeAs('public/images',$image_name);

Laravel Symbolic Link not working

I have some problems creating a symbolic link with laravel to access files that are in my storage
I am storing my files in
storage\app\public
I used the php artisan command to create the link
php artisan storage: link
The [public/storage] directory has been linked.
Earlier files were storing in storage\app\public and were also visible in public\storage folder
But now they are only storing in storage\app\public and not visible in public\storage folder
I am using link to show file path
{{ Storage::url($package->reportPath['path']) }}
Path is showing correct but it redirect to 404 page as there is no file I guess.
This solved it for me on laravel 8, hosted on a ec2 server.
rm public/storage
php artisan optimize:clear
php artisan storage:link
Try removing your public/storage directory and try running storage:link again. This worked for me.
If you are trying to Show the stored file use asset()
asset('storage/further_path/').$file_name;
To store file you can do
$destinationPath = storage_path('app/public/further_path');
if (!is_dir($destinationPath)) {
mkdir($destinationPath, 0777, TRUE);
}
$request->file->move($destinationPath,$filename);
Hope this Helps You.
Let me Know if You have any problem.

Resources