hxy2015/yii2-oss

Oss integration for the Yii framework

Installs: 5

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.0.0 2017-09-04 15:10 UTC

This package is not auto-updated.

Last update: 2025-06-08 08:01:13 UTC


README

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist hxy2015/yii2-oss

or add

"hxy2015/yii2-oss": "~1.0"

to the require section of your composer.json.

Configuration

To use this extension, you have to configure the Connection class in your application configuration:

return [
    //....
    'components' => [
        'oss' => [
            'hostname' => 'localhost',
            'bucket' => 'risk-test',
            'accessId' => 'test', // oss id
            'accessKey' => 'test', // oss id
        ],
    ]
];

Usage

Upload File

$oss = \Yii::$app->get('oss');
$oss->putObjectByContent('some_dir/some_file_name', 'hehe');

$filename = 'test.txt';
file_put_contents($filename, 'hehe');
$oss->putObjectByFile('some_dir/some_file_name', $filename);

Download File

$oss = \Yii::$app->get('oss');
$oss->getObjectContent('some_dir/some_file_name');

$filename = 'test.txt';
$oss->getObjectFile('some_dir/some_file_name', $filename);

Test File Exist

$oss = \Yii::$app->get('oss');
$oss->isObjectExist('some_dir/some_file_name');