File upload to s3 not working after setting visibility to public
08:03 04 May 2022

Trying to configure Laravel to upload to my aws s3 bucket. It is working fine until I change visibility to public. Then it seems to work or at least it does not show any error but nothing gets uploaded to aws.

Here is the part in my register controller where I am uploading a profile picture

       if($request->hasFile('avatar')) {
            $file = $request->file('avatar');
            $filename = $file->getClientOriginalName();

            $file->storeAs('avatars/' . $user->id, $filename, 's3');

            $user->update([
                'avatar' => $filename,
            ]);
        }

And here is the configuration for s3 in filesystems.php

        '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,
        'visibility' => 'public',
    ],

Without the 'visibility' => 'public', it is working fine but as soon as I add it nothing gets uploaded anymore.

laravel amazon-web-services amazon-s3 file-upload