bigdropinc/yii2-cloudstorage

Common interface for amazon s3 and rackspace cloud files

dev-master 2016-05-13 16:30 UTC

This package is not auto-updated.

Last update: 2024-11-13 20:13:23 UTC


README

Common interface for amazon s3 and rackspace cloud files.

Configuration

Amazon S3

Once the extension is installed, simply modify your application configuration as follows:

return [
    //...
    'components' => [
        //...
        'cloudStorage' => [
            'class' => 'bigdropinc\cloudStorage\AmazonS3',
            'key' => '***',
            'secret' => '***',
            'bucket' => 'bucket name',
            //fill this attribute, if you know the base url of your bucket
            'cloudStorageBaseUrl' => 'http://site.s3.amazon.com/'
        ],
    ],
];

Rackspace Cloud Files

Once the extension is installed, simply modify your application configuration as follows:

return [
    //...
    'components' => [
        //...
        'cloudStorage' => [
            'class' => 'bigdropinc\cloudStorage\RackspaceCloudFiles',
            'username' => '***',
            'apiKey' => '***',
            'region' => 'LON',
            'containerName' => 'container name',
            //fill this attribute, if you know the base url of your container
            'cloudStorageBaseUrl' => 'http://site.rackspace.com/'
        ],
    ],
];

Usage

Uploading Files

$file = '@frontend/web/media/image.png';
Yii::$app->cloudStorage->upload($file);

Downloading Files

$name = 'media/image.png';
$dir = '@frontend/web/tmp';
Yii::$app->cloudStorage->download($name, $dir);

Deleting Files

$name = 'media/image.png';
Yii::$app->cloudStorage->delete($name);

Getting Public Url

$name = 'media/image.png';
Yii::$app->cloudStorage->getPublicUrl($name);