PHPackages                             mamadali/yii2-s3-storage - 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. mamadali/yii2-s3-storage

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

mamadali/yii2-s3-storage
========================

A package for yii2 to store files on s3 storage

1.0.1(1y ago)0271MITPHPPHP ^8.0

Since Sep 8Pushed 1y ago1 watchersCompare

[ Source](https://github.com/MamadAliGit/yii2-s3-storage)[ Packagist](https://packagist.org/packages/mamadali/yii2-s3-storage)[ RSS](/packages/mamadali-yii2-s3-storage/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (2)Versions (3)Used By (0)

Yii2 S3 Storage
===============

[](#yii2-s3-storage)

Yii2 S3 Storage is a Yii2 component that provides an easy way to store files on Amazon S3.

[![Latest Stable Version](https://camo.githubusercontent.com/7538539b0a8b0bd66f5f225fcbfc1a0807ef1f7cb30624a541d1ba5b216aad93/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f6d616d6164616c692f796969322d73332d73746f726167652e737667)](https://packagist.org/packages/mamadali/yii2-s3-storage)[![Total Downloads](https://camo.githubusercontent.com/b59635f627a51cb25b7c04fc7b40eacf83de1d98b148c1ae4f1057e368ad17f2/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6d616d6164616c692f796969322d73332d73746f726167652e737667)](https://packagist.org/packages/mamadali/yii2-s3-storage)

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

[](#installation)

The preferred way to install this extension is through [composer](http://getcomposer.org/download/).

Either run

```
composer require mamadali/yii2-s3-storage

```

or add

```
"mamadali/yii2-s3-storage": "*"

```

to the require section of your `composer.json` file. and run `composer update`

then run migrations

```
php yii migrate/up --migrationPath=@vendor/mamadali/yii2-s3-storage/src/migrations

```

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

[](#basic-usage)

add s3 component to `components` section of config file

```
    'components' => [
        ...
        's3storage' => [
            'class' => 'mamadali\S3Storage\components\S3Storage',
            'key' => // your access key
            'secret' => // your secret key
            'endpoint' => // your endpoint
            'default_bucket_name' => // your bucket name
            'bucket_domain' => // Optional: your bucket domain
        ],
        ...
    ];
```

add behavior to your model

```
    public function behaviors()
    {
        return [
            ...
            [
                'class' => StorageUploadBehavior::class,
                'attributes' => ['file'],
                'scenarios' => [self::SCENARIO_UPLOAD],
                'path' => 'path/model_class/{id}'
            ],
            ...
        ];
    }
```

then just add file input to your form and save model in controller

```
