Jim_Chen 2018-08-31 19:16:01 3135次浏览 0条评论 0 0 0

Github

github:https://github.com/JimChenWYU/yii2-flysystem-aliyun-oss

安装

composer require jimchen/yii2-flysystem-aliyun-oss

使用

在配置文件 config.php 的 component 添加:

return [
    //...
    'components' => [
        //...
        'ossFs' => [
            'class' => 'jimchen\flysystem\AliyunOssFilesystem',
            'key' => '您阿里云的 accessKeyId',
            'secret' => '您阿里云的 access=SecretId',
            'bucket' => '您的 Bucket',
            'endpoint' => '您阿里云 OSS 的 endpoint 地址',
            // 'isCName' => false,
            // 'securityToken' => null,
            // 'requestProxy' => null,
            // 'prefix' => 'your-prefix',
            // 'options' => [],
        ],
    ],
];

在您的代码可以这样使用

Yii::$app->ossFs->write('test.txt', 'test content.'); // 往OSS写入,那么在你的bucket上就会存在prefix/text.txt的对象,prefix 为上面指定的前缀。

这里 write 的 API 其实是根据 thephpleague/flysystem 约定,更多 API 可查看 here

注意:阿里云OSS没有提供类似删除特定前缀的对象API,类似于删除文件夹的概念,故本SDK中 deleteDir 没有实现,设定永远返回 false

    没有找到数据。
您需要登录后才可以评论。登录 | 立即注册