Laravel App Storage Images Failed to Load and Redirect to 404

Laravel app storage images failed to load and redirect to 404

1) To store file in laravelapp/storage/app/public/cover/ folder

 use Illuminate\Support\Facades\Storage;
$path=$request->file('cover_image')->storeAs('public/cover_images',$fileNameToStore);

2) To store file in laravelapp/public/cover/ folder

 $path=request()->cover_image->move(public_path('storage/profile'), $fileNameToStore);

in shared hosting server there are 2 folders :

laravelapp and public_html

As im using 2nd way to upload image , I have solved this issue by creating symlink from laravelapp/public/storage folder to public_html/

ln -s /home/username/laravelapp/public/storage  /home/username/public_html/

Fail to load an image from storage on laravel

I guess it's your laravel project diectory bring about this problem.

Asset helper extract your image、js from laravel default public folder.

Copy a image to default public folder and try it again :)

https://laravel.com/docs/9.x/helpers#method-asset

Laravel storage link keep redirected to /public directory in hosting

You can create .htaccess in your root and add these lines and check.

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ /public/$1 [L,QSA]

Error 404 with files created by my Laravel application

Finally, it was my own stupid novice error... The problem was I was not persisting the data outside the docker container, so when I uploaded an image it was stored only in the application container, making it not visible for the host or the nginx container, so the solution was as easy as persisting data in the host and make it accessible from the containers:

services:

app:
container_name: laravel_app
build:
context: ./
dockerfile: development/app.dockerfile
volumes:
- ./storage:/var/www/storage
- ./public/images:/var/www/public/images
env_file: '.env.dev'
environment:
- "DB_HOST=database"
- "REDIS_HOST=cache"

web:
container_name: nginx_server
build:
context: ./
dockerfile: development/web.dockerfile
volumes:
- ./storage/logs/:/var/log/nginx
- ./public/images:/var/www/public/images
ports:
- 80:80

I just added the second line on each "volumes" section and everything began to work properly. I leave it here in case it could help another novice in Laravel + Docker + Nginx. Thanks @amit dahiya for helping me!

404 error on Laravel after uploading a file

In the URL to refer to some file on public folder, don't put the public folder, the laravel path starts from this folder.

example.com/images/covers/d3QCvZT8DilZm7qQ5moHMJa1jeC.jpg



Related Topics



Leave a reply



Submit