Class ‘App\Controller\Aws\S3\S3Client’ not found error in CakePHP 3.*

How to resolve “Class ‘App\Controller\Aws\S3\S3Client’ not found” error in CakePHP 3.*

error in CakePHP 3
Problem: Class ‘App\Controller\Aws\S3\S3Client’ not found error occurs when we are trying to create S3Client class object with given code (code copied from github):

$s3 = new Aws\S3\S3Client ( [ 
	'version' => '2006-03-01',
	'region' => 'us-east-1' 
] );

This code is working fine in Core PHP project but it throws this error in CakePHP 3.*. – Class ‘App\Controller\Aws\S3\S3Client’ not found

Solution: We can resolve it by replacing the above code with the one given below.

use Aws\S3\S3Client;
$s3 = S3Client::factory ( [ 
'credentials' => [ 
		'key' => ‘AWS_ACCESS_KEY_ID’,
		'secret' => ‘AWS_SECRET_ACCESS_KEY’ 
	],
	'region' => 'us-west-2',
	'version' => '2006-03-01' 
] );
OR
use Aws\S3\S3Client;
$s3 = new S3Client ( [ 
	'version' => '2006-03-01',
	'region' => 'us-east-1' 
] );

Leave a Reply

Your email address will not be published. Required fields are marked *