forked from LiveCarta/yii2-aws-s3
This repository has been archived on 2026-04-06 . You can view files and clone it. You cannot open issues or pull requests or push a commit.
9cfd06866ea6dd44a66e718949a024c644cd4fc6
Yii2 AWS S3
An Amazon S3 component for Yii2.
Installation
-
Run the Composer command to install the latest stable version:
composer require frostealth/yii2-aws-s3 ~2.0@stable -
Add the component to
config/main.php'components' => [ // ... 's3' => [ 'class' => 'frostealth\yii2\aws\s3\Service', 'credentials' => [ // Aws\Credentials\CredentialsInterface|array|callable 'key' => 'my-key', 'secret' => 'my-secret', ], 'region' => 'my-region', 'defaultBucket' => 'my-bucket', 'defaultAcl' => 'public-read', ], // ... ],
Basic usage
Usage the command factory and additional params
/** @var \frostealth\yii2\aws\s3\Service $s3 */
$s3 = Yii::$app->get('s3');
/** @var \Aws\ResultInterface $result */
$result = $s3->commands()->get('filename.ext')->saveAs('/path/to/local/file.ext')->execute();
$result = $s3->commands()->put('filename.ext', 'body')->setContentType('text/plain')->execute();
$result = $s3->commands()->delete('filename.ext')->execute();
$result = $s3->commands()->upload('filename.ext', '/path/to/local/file.ext')->setAcl('private')->execute();
$result = $s3->commands()->restore('filename.ext', $days = 7)->execute();
$isExisting = $s3->commands()->exist('filename.ext')->execute();
$url = $s3->commands()->getUrl('filename.ext')->execute();
$signedUrl = $s3->commands()->getPresignedUrl('filename.ext', '+2 days')->execute();
Short syntax
/** @var \frostealth\yii2\aws\s3\Service $s3 */
$s3 = Yii::$app->get('s3');
/** @var \Aws\ResultInterface $result */
$result = $s3->get('filename.ext');
$result = $s3->put('filename.ext', 'body');
$result = $s3->delete('filename.ext');
$result = $s3->upload('filename.ext', '/path/to/local/file.ext');
$result = $s3->restore('filename.ext', $days = 7);
$isExisting = $s3->exist('filename.ext');
$url = $s3->getUrl('filename.ext');
$signedUrl = $s3->getPresignedUrl('filename.ext', '+2 days');
Asynchronous execution
/** @var \frostealth\yii2\aws\s3\Service $s3 */
$s3 = Yii::$app->get('s3');
/** @var \GuzzleHttp\Promise\PromiseInterface $promise */
$promise = $s3->commands()->get('filename.ext')->async()->execute();
$promise = $s3->commands()->put('filename.ext', 'body')->async()->execute();
$promise = $s3->commands()->delete('filename.ext')->async()->execute();
$promise = $s3->commands()->upload('filename.ext', 'source')->async()->execute();
License
Yii2 AWS S3 is licensed under the MIT License. See the LICENSE.md file for more information.
Description
Languages
PHP
100%