rvkvino's avatar

I have an issue on retrieve the image from the storage folder

I have written the code as like below to store the image into my server folder. I have an application written the API by using lumen and using front end as Mobile app developed by using ionic3. I could take the picture and store into server by the below code, $image = $request->file('photo'); $name = $image->getClientOriginalName(); $destinationPath = storage_path('/app/images/kyc'); if($image->move($destinationPath, $name)){ //Success the file upload means storing the file name into DB table } Now I need to reterive this profile picture to mobile app and need to display image. I have tried like http://mydomain.com/storage/app/profile/filename.png but it didn't work and showing like {"error":true,"message":"Unauthorized Request"}

0 likes
3 replies
xmarks's avatar

You can not access the storage folder directly like that. It is 1-level above the public path where your index.php file is located.

You should read this doc: https://laravel.com/docs/5.6/filesystem#configuration

Basically you have to create a symbolic link:

php artisan storage:link

Then you access files using the Storage facade:

  • Storage::put('avatars/1', $fileContents);
  • $contents = Storage::get('file.jpg');
  • $url = Storage::url('file.jpg');
rvkvino's avatar

@xmarks I have tried this already It shows storage command as There are no commands defined in the "storage" namespace. I'm using lumen API. And when I try like

$url = Storage::url('/app/public/profile/' . $fileName);
return response()->json(['error' => false, 'url' => $url]);

shows error Driver [] is not supported. For this I have added the code,

config([
    "filesystems" => [
        'default' => 'local',
        'disks' => [
            'local' => [
                'driver' => 'local',
                'root' => storage_path('app'),
            ],
        ],
    ],
]);

Then it shows the error like Class 'League\Flysystem\Adapter\Local' not found

biishmar's avatar

@rvkvino

make sure lumen have a storage facility, i think u have get that package seperately..

Please or to participate in this conversation.