search

Home  >  Q&A  >  body text

Laravel public storage returns 404 for images

Following the Laravel documentation (I'm using Laravel with docker using sail), I created a symlink for storage php artisan storage:link. I also tried recreating the link using the full path starting from the root directory.

Then I store a file

// ...
$filename = 'signatures/signature_' . auth()->user()->id . '-' . uniqid() . '.' . $image_type;
Storage::disk('public')->put($filename, $image_base64);

After that I can successfully open my file from the console:

open public/storage/signatures/signature_101-62a876ce68884.png

When I try to access the if from my url, I receive a 404:

http://laravel.test/storage/signatures/signature_101-62a876ce68884.png

I noticed by trying to display the image:

<img src="{{ url('/storage/' . $clients->signature->filename) }}">

I finally tried it

rm public/storage
php artisan optimize:clear
php artisan storage:link

did not succeed

P粉798343415P粉798343415371 days ago495

reply all(1)I'll reply

  • P粉799885311

    P粉7998853112023-12-13 09:25:59

    I found the solution. Laravel recommends using sail first, but the documentation doesn't cover this behavior.

    The symbolic link must be created in the container!

    In the root directory of the project:

    • rm public/storage
    • docker exec -it php artisan storage: link

    reply
    0
  • Cancelreply