grigorieff/yii2-aws

此软件包最新版本(dev-master)没有提供许可信息。

用于亚马逊云服务的Yii2组件

dev-master 2014-12-21 19:57 UTC

This package is not auto-updated.

Last update: 2024-09-28 17:02:08 UTC


README

安装

安装此扩展的首选方式是通过 composer

可以运行

php composer.phar require --prefer-dist grigorieff/yii2-aws "master-dev"

或者将以下内容添加到你的 composer.json 文件的 require 部分:

"grigorieff/yii2-aws": "*"

配置

添加到你的应用配置中

    'components' => [

        .........

        'aws' => [
            'class' => grigorieff\aws\AWSComponent,
            'key' => '......',
            'secret' => '......',
            'region' => '......'
        ],

        .........

    ];

使用方法

$aws = Yii::$app->aws;

// AWS S3

$s3 = $aws->get('s3');

try {
    $s3->putObject(array(
        'Bucket' => 'my-bucket',
        'Key'    => 'my-object',
        'Body'   => fopen('/path/to/file', 'r'),
        'ACL'    => 'public-read',
    ));
} catch (S3Exception $e) {
    echo "There was an error uploading the file.\n";
}

......

try {
    $resource = fopen('/path/to/file', 'r');
    $s3->upload('my-bucket', 'my-object', $resource, 'public-read');
} catch (S3Exception $e) {
    echo "There was an error uploading the file.\n";
}

......

$s3->getObject(array(
    'Bucket' => $bucket,
    'Key'    => 'data.txt',
    'SaveAs' => '/tmp/data.txt'
));
echo $result['Body']->getUri() . "\n";