grptx/yii2-s3client

安装: 119

依赖: 0

建议者: 0

安全: 0

星星: 1

关注者: 1

分支: 1

开放问题: 0

类型:yii2-component

v1.3.0 2019-10-16 12:51 UTC

This package is auto-updated.

Last update: 2024-09-17 00:24:29 UTC


README

Latest Stable Version Total Downloads Latest Unstable Version License composer.lock available

基于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)