Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel: Can't visualize an image on Storage::

First things first, I upload an image to a Storage:: in the controller like this:

$ranker = Ranker::create([ ... ]);

if ($request->file('file')) {
  $filename = Storage::put('ranker', $request->file('file');
  $ranker->image_url = $filename;
  $ranker->save();
}

So this is working, in the database I got a url in the proper field, something like: ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png. If I go to \app\Storage\app\ranker I see the file, and it is correctly uploaded.

Now, when I want to render the file I do something simple as:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<img src="{{ Storage::url($ranker->image_url) }}" ... >

The src correctly says: /storage/ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png but displays nothing. If I go to http://server/storage/ranker/v14rzsqJjlJIEYG2Cd22l1MLxeNPd0hGI0rvLjrf.png I got a 404

Any ideas?

>Solution :

The Storage folder is not a publicly accessible folder, so you either need to save the image in the public directory or link the storage public folder to the public folder by running the following artisan command in the cli.

php artisan storage:link

Then when saving you need to add it to the public folder by choosing the public disk as default or selecting the disk like this

Storage::disk('public')->put('ranker', $request->file('file'));

And then output:-

{{ Storage::disk('public')->url($ranker->image_url) }}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading