maxluzon's avatar

Error Displaying uploaded image: NotFoundHttpException in RouteCollection.php line 179:

hello, I am trying to display images that my app is currently uploading. But I am having the error: NotFoundHttpException in RouteCollection.php line 179:

The images are stored at: app/public/properties/1/

for example: app/public/properties/1/1496879400593891289226c.jpg

None of this work:

<img src="public/properties/1/1496879400593891289226c.jpg"/>
<img src="{{url('public/properties/1/1496879400593891289226c.jpg')}}"/>
<img src="{{asset(url('public/properties/1/1496879400593891289226c.jpg'))}}"/> 
<img src="properties/1/1496879400593891289226c.jpg"/> 

Thanks in advanced for your help!

0 likes
6 replies
michaelrtm's avatar

Is the image definitely there?

Does your server have read permissions to the folder?

When you say app/public/, do you mean like /var/www/Project_name/public or /var/www/Project_name/app/public? (Just double checking)

Have you considered using Storage::? https://laravel.com/docs/5.4/filesystem

https://stackoverflow.com/questions/27300431/notfoundhttpexception-when-trying-to-access-image

https://laracasts.com/discuss/channels/laravel/image-urls-giving-notfoundhttpexception-in-routecollectionphp-line-161

maxluzon's avatar

Hello @michaelrtm, next are the answers to your questions:

  1. The images are there.
  2. the permissions were granted to all directories under public folder:
sudo chmod -R guo+w storage

  1. I mean /var/www/html/Project_name/storage/app/public/

  2. I've check Storage,

Apperantly it is trying to check if there is any route defined for the url, it is not treating it as file/asset/resources. Maybe I have to set some config to the app server.

Thanks,

MaverickChan's avatar

no , you stored the file in wrong place.

those files should be in /var/www/html/Project_name/public/properties/1/anything.jpg

then in your view

<img src="{{url('/properties/1/1496879400593891289226c.jpg')}}"/>

the first slash is better added

michaelrtm's avatar

Have you created a symlink from /var/www/html/Project_name/storage/app/public/ to /var/www/html/Project_name/public??

php artisan storage:link
1 like
Snapey's avatar
Snapey
Best Answer
Level 122

Wow, what a lot of seemingly contradictory advice.

The main consideration is that the images need to be in a place where the browser can get to them - i.e., on the public side of your web site.

You cannot just create a folder within app and hope that the images will be visible to the outside world.

The simplest solution is to place them in your project/public folder and then access them with, e.g., <img src="/imagesfolder/image.jpg">

This is only true though if you have correctly set the document root to be the public folder.

The more complicated solution is to put them in the storage public folder and then create a symbolic link so that they appear to be in the project/public folder.

Ignore all the helper methods for now. Just type the path to the image in your browser address bar. Make sure you understand where the images are from the browsers perspective.

1 like
maxluzon's avatar

Thank you very much @snapey and @michaelrtm. I was confused with the usage of the folders storage/app/public and app/public.

I am using the storage/app/public folder, since the documentation says that this folder may be used to store user-generated files, such as profile avatars, that should be publicly accessible.

But I haven't created the symbolic link. I will try it out with the symlink, and check if it would be accesible.

Thank you for your help!

Please or to participate in this conversation.