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
.
Plugin::load('CakeS3');
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' => 'CakeS3\Datasource\Connection',
'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.
<?php
namespace App\Model\Table;
use CakeS3\Datasource\AwsS3Table;
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');
$this->response->type('image/jpeg');
$this->response->body($content);
return $this->response;
}
}
The methods can call on your S3 Table.
If You want more detail, go to S3Client document. http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html