grptx / yii2-s3client
v1.3.0
2019-10-16 12:51 UTC
Requires
- aws/aws-sdk-php: ^3
- yiisoft/yii2: ^2
README
基于klinson/aws-s3-minio的Yii2 S3Client
安装
首选安装方式是通过Composer
php composer.phar require grptx/yii2-s3client:^1
或者,您可以在您的composer.json
文件的require部分添加
"grptx/yii2-s3client": "^1"
并执行php composer.phar update
。
配置
在web.php
中
'components'=> [ 's3client' => [ 'class'=> 'grptx\S3Client', 'key' => '<your key>', 'secret' => '<yout secret>', 'endpoint'=> '<your endpoint>', 'region' => '<your region>', 'defaultBucket' => '<bucket>', //optional default bucket 'debug' => false, // optional 'http' => [ //optional 'verify' => false //use false to self-signed certs ], ], ],
使用
/** @var S3Client $s3client */
$s3client = Yii::$app->s3client;
/**
* put file to minio/s3 server
*
* @param string $localObjectPath full path to file to put
* @param string|null $storageSavePath full path to file in bucket (optional)
* @param string|null $bucket the bucket name (optional)
* @param array $meta (optional)
* @return Result|bool
*/
$s3client->putObjectByPath(string $localObjectPath, string $storageSavePath = null, string $bucket = null, array $meta = []);
/**
* create and put a file into minio/s3 server with the specified content
*
* @param string $content
* @param string $storageSavePath
* @param string $bucket
* @param array $meta
* @return Result|bool
*/
$s3client->putObjectByContent(string $content, string $storageSavePath, string $bucket = null, array $meta = []);
/**
* get file object from minio/s3 server
*
* @param string $storageSavePath
* @param string|null $localSaveAsPath
* @param string|null $bucket
* @return bool|mixed
*/
$s3client->getObject(string $storageSavePath, string $localSaveAsPath = null, string $bucket = null)