ottaviane's avatar

[SOLVED] Uploading file to a disk not working

Hi all, I'm struggling with this problem: I'd like to upload an image to a specific disk in Laravel 7. I configured this disk in filesystem.php

 'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],
        'DocsImg' => [
            'driver' => 'local',
            'root' => storage_path('app/Documents/img'),
            'url' => env('APP_URL').'/DocsImg',
            'visibility' => 'public',
        ],

        's3' => [
            'driver' => 's3',
            'key' => env('AWS_ACCESS_KEY_ID'),
            'secret' => env('AWS_SECRET_ACCESS_KEY'),
            'region' => env('AWS_DEFAULT_REGION'),
            'bucket' => env('AWS_BUCKET'),
            'url' => env('AWS_URL'),
            'endpoint' => env('AWS_ENDPOINT'),
        ],

and in my controller I do this:

 public function addFoto(Request $request){      
            $uploadedFile=$request->file('image');
            $path = $uploadedFile->store('image','DocsImg');
            return response()->json(['esito' =>"OK" , 'path' => $path],200);
    }

but I receive a 500 error! Instead if I do so

 $path = $uploadedFile->store('image');

It works fine. But I need to specify a disk! Why? What can I do? Hello and thanks

0 likes
1 reply
ottaviane's avatar
ottaviane
OP
Best Answer
Level 1

SOLVED! it was all correct. The solution was in the rights of the directory:

sudo chown -R www-data:ottaviane path_project
sudo chmod -R 775 path_project

solved all!

1 like

Please or to participate in this conversation.