0

So im currently working on a simple REST API in Laravel. I have a post function which sends entered data to database and uploads one file. Everything works fine on local. Image is uploading to storage/public/my_directory. I also have public access to the uploaded image by going to address "localhost://storage/my_directory/my_file.jpg". The problem is that after deploying the project to shared hosting i cant upload files. Im just getting this meaningless error

Thats how my function looks like:

public function store(Request $request)
{
        $request->validate([
            'name' => 'required',
            'slug' => 'required',
            'description' => 'required',
            'country' => 'required',
            'file' => 'required|image',
            'category' => 'required',
        ]);

        $img = $request->file('file')->store('public/images');
        $request->merge(['image' => $img]);

        $product = Product::create($request->all());

        return dd($product);
}

And additionally filesystems.php file:

'disks' => [

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

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

        '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'),
            'use_path_style_endpoint' => env('AWS_USE_PATH_STYLE_ENDPOINT', false),
            'throw' => false,
        ],

    ],

Any suggestions?

3
  • 1
    Somewhere there are some logs that hopefully have some more detail. Perhaps there is a permissions error or something like that but the logs should point you in the right direction. Commented Jul 17, 2023 at 18:58
  • How big is the file? What's your upload_max_filesize and post_max_size setting? Commented Jul 17, 2023 at 19:01
  • @ceejayoz i was afraid that file size might be too big but it also fails even with 200byte image Commented Jul 17, 2023 at 19:42

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.