PHPackages                             dudecussi/yii2-aws-s3 - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. dudecussi/yii2-aws-s3

ActiveYii2-extension[File &amp; Storage](/categories/file-storage)

dudecussi/yii2-aws-s3
=====================

An Amazon S3 component for Yii2

0.1.1(4y ago)09MITPHPPHP &gt;=7.0.0

Since Jan 31Pushed 4y ago1 watchersCompare

[ Source](https://github.com/dudecussi/yii2-aws-s3)[ Packagist](https://packagist.org/packages/dudecussi/yii2-aws-s3)[ Docs](https://github.com/dudecussi/yii2-aws-s3)[ RSS](/packages/dudecussi-yii2-aws-s3/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (4)Versions (3)Used By (0)

Yii2 AWS S3
===========

[](#yii2-aws-s3)

An Amazon S3 component for Yii2.

[![License](https://camo.githubusercontent.com/b1f7d5f9682888d2fe85e2683d7b7cc3ab38d6831995c6a3ae0cd126e154fb48/68747470733a2f2f706f7365722e707567782e6f72672f6475646563757373692f796969322d6177732d73332f6c6963656e7365)](https://github.com/dudecussi/yii2-aws-s3/blob/2.x/LICENSE) [![Latest Stable Version](https://camo.githubusercontent.com/f9b5098b32433a58abd6eb0d1c1fc48bee139727980d1b20cd9f17ddf66de712/68747470733a2f2f706f7365722e707567782e6f72672f6475646563757373692f796969322d6177732d73332f76)](//packagist.org/packages/dudecussi/yii2-aws-s3) [![Total Downloads](https://camo.githubusercontent.com/c7ff20cf39633cc8acde380a4139fdf3f66971ae70f337953cd32906eb96ca63/68747470733a2f2f706f7365722e707567782e6f72672f6475646563757373692f796969322d6177732d73332f646f776e6c6f616473)](//packagist.org/packages/dudecussi/yii2-aws-s3) [![Latest Unstable Version](https://camo.githubusercontent.com/6b639e297a041fe19042ed0bf2101f2bfdd2e15ae7c1e995ed3013c63291b52b/68747470733a2f2f706f7365722e707567782e6f72672f6475646563757373692f796969322d6177732d73332f762f756e737461626c65)](//packagist.org/packages/dudecussi/yii2-aws-s3)

> Yii2 AWS S3 uses [SemVer](http://semver.org/).

> Version 2.x requires PHP 7. For PHP less 7.0 use [1.x](https://github.com/dudecussi/yii2-aws-s3/tree/1.x).

About this project
------------------

[](#about-this-project)

This project is a fork from the excellent project [yii2-aws-s3](https://github.com/frostealth/yii2-aws-s3) by [frostealth](https://github.com/frostealth) and [adnsio](https://github.com/adnsio).

Upon their work, we add support for IAM role attached to the EC2, which you don't need to insert your credentials.

We will also add support for easier integration with your models, by adding a S3MediaTrait.

Installation
------------

[](#installation)

1. Run the [Composer](http://getcomposer.org/download/) command to install the latest version:

    ```
    composer require dudecussi/yii2-aws-s3 ~2.0
    ```
2. Add the component to `config/main.php`

    ```
    'components' => [
        // ...
        's3' => [
            'class' => 'dudecussi\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',
            'defaultPresignedExpiration' => '+1 hour',
        ],
        // ...
    ],
    ```

**Credentials parameter is optional**: if you plan to use IAM roles attached to your EC2 instance there is no need for credentials. Just remove this parameter. Just be cautious if you need those credentials, this may cause errors during execution.

Basic usage
-----------

[](#basic-usage)

### Usage of the command factory and additional params

[](#usage-of-the-command-factory-and-additional-params)

```
/** @var \dudecussi\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')->withContentType('text/plain')->execute();

$result = $s3->commands()->delete('filename.ext')->execute();

$result = $s3->commands()->upload('filename.ext', '/path/to/local/file.ext')->withAcl('private')->execute();

$result = $s3->commands()->restore('filename.ext', $days = 7)->execute();

$result = $s3->commands()->list('path/')->execute();

/** @var bool $exist */
$exist = $s3->commands()->exist('filename.ext')->execute();

/** @var string $url */
$url = $s3->commands()->getUrl('filename.ext')->execute();

/** @var string $signedUrl */
$signedUrl = $s3->commands()->getPresignedUrl('filename.ext', '+2 days')->execute();
```

### Short syntax

[](#short-syntax)

```
/** @var \dudecussi\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);

$result = $s3->list('path/');

/** @var bool $exist */
$exist = $s3->exist('filename.ext');

/** @var string $url */
$url = $s3->getUrl('filename.ext');

/** @var string $signedUrl */
$signedUrl = $s3->getPresignedUrl('filename.ext', '+2 days'); // Pass only one parameter to get expiration date from component defaults
```

[Read more...](/docs/basic-usage.md)

Advanced usage
--------------

[](#advanced-usage)

```
/** @var \dudecussi\yii2\aws\s3\interfaces\Service $s3 */
$s3 = Yii::$app->get('s3');

/** @var \dudecussi\yii2\aws\s3\commands\GetCommand $command */
$command = $s3->create(GetCommand::class);
$command->inBucket('my-another-bucket')->byFilename('filename.ext')->saveAs('/path/to/local/file.ext');

/** @var \Aws\ResultInterface $result */
$result = $s3->execute($command);

// or async
/** @var \GuzzleHttp\Promise\PromiseInterface $promise */
$promise = $s3->execute($command->async());
```

[Read more...](/docs/advanced-usage.md)

Using Traits
------------

[](#using-traits)

Attach the Trait to the model with some media attribute that will be saved in S3:

```
class Person extends \yii\db\ActiveRecord
{
    use \dudecussi\yii2\aws\s3\traits\S3MediaTrait;

    // ...
}
```

```
$image = \yii\web\UploadedFile::getInstance( $formModel, 'my_file_attribute' );
// Save image as my_image.png on S3 at //my_bucket/images/ path
// $model->image will hold "my_image.png" after this call finish with success
$model->saveUploadedFile( $image, 'image', 'my_image.png' );

// Get the URL to the image on S3
$model->getFileUrl( 'image' );
// Get the presigned URL to the image on S3
// The default duration is "+1 day"
$model->getFilePresignedUrl( 'image' );

// Remove the file with named saved on the image attribute
// Continuing the example, here "//my_bucket/images/my_image.png" will be deleted from S3
$model->removeFile( 'image' );

// Save my_image.* to S3 on //my_bucket/images/ path
// The extension of the file will be determined by the submitted file type
// This allows multiple file types upload (png,jpg,gif,...)
$model->saveUploadedFile( $image, 'image', 'my_image', true );
```

[Read more...](/docs/media-traits.md)

License
-------

[](#license)

Yii2 AWS S3 is licensed under the MIT License.

See the [LICENSE](LICENSE) file for more information.

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity35

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

1563d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/559147dd61cee1f80c04887b74162e808714b936f2a8fee16e4a65f237a55f37?d=identicon)[dudecussi](/maintainers/dudecussi)

---

Top Contributors

[![dudecussi](https://avatars.githubusercontent.com/u/5396404?v=4)](https://github.com/dudecussi "dudecussi (2 commits)")

---

Tags

s3awsyii2aws-s3yii2-s3yii2-aws

###  Code Quality

Code StylePHP\_CodeSniffer

### Embed Badge

![Health badge](/badges/dudecussi-yii2-aws-s3/health.svg)

```
[![Health](https://phpackages.com/badges/dudecussi-yii2-aws-s3/health.svg)](https://phpackages.com/packages/dudecussi-yii2-aws-s3)
```

###  Alternatives

[frostealth/yii2-aws-s3

An Amazon S3 component for Yii2

90698.9k5](/packages/frostealth-yii2-aws-s3)[fedemotta/yii2-aws-sdk

This extension provides the AWS SDK integration for the Yii2 framework

15430.4k2](/packages/fedemotta-yii2-aws-sdk)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
