phplaravelimagesambafile-storage

How to display image from another disk in Laravel


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?


Solution

  • 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')}}">