AWS S3 datasource in CakePHP3

AWS S3 datasource in CakePHP3



This CakePHP 3.0 plugin provides AWS S3 Datasource.


Install Plugin using composer.

$ composer require "sters/cakephp3-aws-s3-datasource:dev-master"

Add Plugin::load() on your config/bootstrap.php.


Add S3 Datasource on your config/app.php.

one Datasrouce has one S3 Bucket connection.
You can not across bucket processing.

'Datasource' => [
    'my_s3_connection' => [
        'className'  => 'CakeS3DatasourceConnection',
        'key'        => 'put your s3 access key',
        'secret'     => 'put your s3 access secret',
        'bucketName' => 'put your bucket name',
        'region'     => 'put your region',

Setup new table using s3 connection.

$_connectionName is your wrote connection name in config/app.php Datasource.

namespace AppModelTable;

use CakeS3DatasourceAwsS3Table;

class MyS3Table extends AwsS3Table
    protected static $_connectionName = 'my_s3_connection';

For example, declare action of get & show S3 Object.

class TopController extends Controller
    public function index()
        $MyS3Table = TableRegistry::get('MyS3');
        $content = $MyS3Table->getObjectBody('/path/to/object/file.jpg');


        return $this->response;


AwsS3Table support methods

The methods can call on your S3 Table.

If You want more detail, go to S3Client document.

copyObject(string $srcKey, string $destKey, array $options = ) : AwsResult

deleteObject(string $key, array $options = ) : AwsResult

deleteObjects(string $keys, array $options = ) : AwsResult

doesObjectExist(string $key, array $options = ) : bool

getObject(string $key, array $options = ) : AwsResult

headObject(string $key, array $options = ) : AwsResult

putObject(string $key, $content, array $options = ) : AwsResult

getObjectBody(string $key, array $options = ) : GuzzleHttpPsr7Stream

moveObject(string $srcKey, string $destKey, array $options = ) : AwsResult


Add a Comment

Tu dirección de correo electrónico no será publicada. Los campos obligatorios están marcados con *