Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

6ber6ou's avatar

S3 and visibility

Hi All.

I upload a file to S3 with this code :

$path = request()->file( 'file' )->store( 'safe-papers', 's3' );

The file is uploaded but the visibility is set to private by default. How can I set the visibility of the uploaded file to public ?

I tried that but it doesn't work :

Storage::setVisibility( $path, 'public' );
0 likes
2 replies
willvincent's avatar
Level 54

Based on what I see in the FileSystemManager class, adding visibility to the s3 config in config/filesystems.php should let you define the default as public:

's3' => [
            'driver' => 's3',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
            'visibility' => 'public',
        ],

FileSystemManager:

/**
     * Create a Flysystem instance with the given adapter.
     *
     * @param  \League\Flysystem\AdapterInterface  $adapter
     * @param  array  $config
     * @return \League\Flysystem\FlysystemInterface
     */
    protected function createFlysystem(AdapterInterface $adapter, array $config)
    {
        $config = Arr::only($config, ['visibility']);

        return new Flysystem($adapter, count($config) > 0 ? $config : null);
    }
4 likes
madsey_shades's avatar

In case you don't want all files that you upload to S3 to be public, remove the visibility key from the s3 array in your config/filesystems.php file AND use the commands below. This allows you to selectively determine when you want a file to be public or private.

Your New s3 Array Without the Visibility Key

's3' => [
            'driver' => 's3',
            'key' => 'your-key',
            'secret' => 'your-secret',
            'region' => 'your-region',
            'bucket' => 'your-bucket',
        ],

The following commands allow you to upload the file as either public or private.

Make Upload Public:

// Set file upload to public
$path = Storage::disk('s3')->put('directory_name/'.$user->id, $request->file('file_name'), 'public');

Make Upload Private:

// Set file upload to private
$path = Storage::disk('s3')->put('directory_name/'.$user->id, $request->file('file_name'));
3 likes

Please or to participate in this conversation.