sters/cakephp3-aws-s3-datasource

CakePHP3中的AWS S3数据源

资助包维护!
sters

安装次数: 9,312

依赖关系: 0

建议者: 0

安全: 0

星标: 11

关注者: 4

分支: 5

开放问题: 0

类型:cakephp-plugin

0.0.3 2018-05-12 06:19 UTC

This package is auto-updated.

Last update: 2024-09-27 15:48:38 UTC


README

CircleCI

此CakePHP 3.0插件提供AWS S3数据源。

安装

使用composer安装插件。

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

在您的config/bootstrap.php中添加Plugin::load()

Plugin::load('CakeS3');

在您的config/app.php中添加S3数据源。

一个数据源对应一个S3桶的连接。 您不能跨桶处理

'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',
    ],
],

使用s3连接设置新表。

$_connectionName是您在config/app.php数据源中写入的连接名称。

<?php
namespace App\Model\Table;

use CakeS3\Datasource\AwsS3Table;

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

例如,声明获取和显示S3对象的动作。

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;
    }
}

文档

AwsS3Table支持的方法

这些方法可以在您的S3表中调用。

如果您想了解更多详细信息,请参阅S3Client文档。 http://docs.aws.amazon.com/aws-sdk-php/v3/api/class-Aws.S3.S3Client.html

copyObject(string $srcKey, string $destKey, array $options = []) : \Aws\Result

deleteObject(string $key, array $options = []) : \Aws\Result

deleteObjects(string $keys, array $options = []) : \Aws\Result

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

getObject(string $key, array $options = []) : \Aws\Result

headObject(string $key, array $options = []) : \Aws\Result

putObject(string $key, $content, array $options = []) : \Aws\Result

getObjectBody(string $key, array $options = []) : \GuzzleHttp\Psr7\Stream

moveObject(string $srcKey, string $destKey, array $options = []) : \Aws\Result