0

I am trying to display an image in my Laravel application. The image comes from another disk which is a samba share. I followed the configuration instructions from the Laravel Doc, here is my setup:

filesystems.php

'shop_storage' => [
    'driver' => 'local',
    'root' => env('SHOP_STORAGE_PATH', base_path('shop_storage')),
    'dir' => [
        'public' => 0777,
        'private' => 0777,
    ]
],

My samba share is mounted into the root folder /shop_storage inside my Laravel application with the following command: sudo mount.cifs //PATH_TO_FILE_SHARE/ARMMAG ./shop_storage -o credentials=$HOME/.smbcredentials,rw,file_mode=0777,dir_mode=0777,mfsymlinks

I correctly see all files when I open the folder. Then, I added a Symlink from /public/storage to /shop_storage with the following command: sudo ln -s /shop_storage /public/storage (Using full path starting at /home, removed here for privacy) When I open /public/storage, I correctly see the symlink pointing to the samba share. If I click to open it, I see all the files. The file I am looking for exists.

directory structure

The problem is when I am trying to display it in my webpage, the request return a 404. Here is some of the things that I have tried:

<img src="{{\Storage::disk('shop_storage')->url('products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
<img src="http://localhost:8000/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png">
<img src="{{asset('products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">
<img src="{{asset('storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">

What am I doing wrong?

Edit After some try/error, I managed to get a different response with the following syntax: <img src="{{asset('storage/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}"> Now, I am getting the foloowing error

You don't have permission to access /storage/shop_storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png on this server.

My permission are set to 777, what could cause this?

naghal
  • 537
  • 3
  • 19
  • https://laravel-guide.readthedocs.io/en/latest/filesystem/#obtaining-disk-instances ```Remember, if you are using the local driver, all files that should be publicly accessible should be placed in the storage/app/public directory. Furthermore, you should create a symbolic link at public/storage which points to the storage/app/public directory.``` – floGalen Sep 14 '20 at 17:23
  • ```{{ HTML::image('img/stuvi-logo.png', 'alt text', array('class' => 'css-class')) }}``` seen here: https://stackoverflow.com/questions/29858097/laravel-blade-html-image – floGalen Sep 14 '20 at 17:30
  • I don't think this is the solution to my problem. I don't want to store my files under storage/app/public, as stated, I want them to be on my samba share. That's why I created a symlink that points there instead of storage/app/public – naghal Sep 14 '20 at 17:30
  • https://stackoverflow.com/questions/30191330/laravel-5-how-to-access-image-uploaded-in-storage-within-view – floGalen Sep 14 '20 at 17:32

1 Answers1

-1

What I ended up doing to make this work is mount my share directly into public/storage instead of using symlinks. Then any I could access the file using the laravel asset helper:

<img src="{{asset('storage/products/16/MAZJKj59EY0XQ57oKIibKr33eZ5dsqAPx44MCHHJ.png')}}">

naghal
  • 537
  • 3
  • 19