Amrinder Singh
Amrinder Singh

Reputation: 5492

Not able to access image stored in Storage folder in Laravel 5.5

I am trying to access an image in the url which is stored in the /storage folder.

Image Stored Path:

Project/storage/app/public/default.png

According to Laravel 5.5 docs, your publicly accessible files should be put in directory

storage/app/public

So I did the same, but when I try to access the image as:

http://localhost:8000/storage/default.png

then it doesn't work.

I tried the following command:

php artisan storage:link

but it throws an error:

The "public/storage" directory already exists.

Upvotes: 1

Views: 18350

Answers (7)

Yamlak Kassahun
Yamlak Kassahun

Reputation: 23

Try Deleting the storage Folder in the Public Directory and then Run This Command "php artisan storage:link" then try it.

Upvotes: 1

Steve Nyanumba
Steve Nyanumba

Reputation: 164

The best way to do it is to first remove the symlink by running a code that will remove storage from the public folder first like so:

$ rm public/storage

then rerun the symlink code again

$ php artisan storage:link

You will see that afterwards the public/storage folder will reappear and will be updated

Upvotes: 10

Andrew Vink
Andrew Vink

Reputation: 331

Sep 2019

What's working for me:

  • SSH into your homestead VM
  • cd into your project folder
  • php artisan storage:link (As Admin in your terminal)
  • Run successfully I don't see a /storage folder in my /public dir
  • Access images via blade using storage/ in the url eg. "storage/{{ $post->image }}"

If you run into any errors:

  • rm -rf public/storage
  • php artisan storage:link (As Admin in your terminal)

Upvotes: 0

Damian Perez
Damian Perez

Reputation: 554

As for 2019, if any of you got this error:

"The "public/storage" directory already exists."

Then go to your public folder and delete the "storage" file.

Once you do it, run again the "php artisan storage:link" and it will work now

Upvotes: 16

Yllndrit
Yllndrit

Reputation: 57

Try deleting storage folder inside app/public/storage than run the command(php artisan storage:link) again and than you can access file using this path

http://localhost:8000/storage/<folder_name_if_folder_exists>/<file_name>.<extension>

Upvotes: 3

Hiren Gohel
Hiren Gohel

Reputation: 5042

First use php artisan storage:link

Then you can access all public path using /* like:

http://localhost:8000/default.png

Above command allow you to get images directly from public path!

Hope this helps you!

Upvotes: 1

aaron0207
aaron0207

Reputation: 2333

You cannot access files inside storage folder directly as you tried. First you have to create a symbolic link of your storage "public" folder to your real "public" folder.

php artisan storage:link

Try again after the command.

NOTE: If you are using windows open command line (cmd, git bash...) as admin to avoid errors.

Upvotes: 2

Related Questions