kaysonwu / flysystem-aliyun-oss
1.0.0
2019-12-20 14:38 UTC
Requires
- php: >=5.5.9
- aliyuncs/oss-sdk-php: ^2.0
- league/flysystem: ^1.0
Requires (Dev)
- mockery/mockery: 0.9.*
- phpunit/phpunit: ~4.0
This package is auto-updated.
Last update: 2022-02-24 05:17:19 UTC
README
优势
- 支持Laravel & Lumen
- 与xxtime/flysystem-aliyun-oss相比,更符合flysystem接口规范。因为flysystem接口建议返回值为数组或布尔值,但xxtime/flysystem-aliyun-oss对异常处理不是非常严格。
- 与apollopy/flysystem-aliyun-oss <= 1.2.0相比,支持可见性获取/设置。
- 支持动态调用OSS SDK方法。
ps:对类似项目的比较只是为了突出差异。实际上,它们都是非常优秀的。
安装
通过composer安装
运行以下命令以拉取最新版本
composer require kaysonwu/flysystem-aliyun-oss
Laravel安装
如果你的laravel版本 <=5.4
,将服务提供者添加到config/app.php
配置文件中的providers
数组中,如下所示
'providers' => [ ... Kaysonwu\Flysystem\Aliyun\OssServiceProvider::class, ]
Lumen安装
将以下片段添加到bootstrap/app.php
文件中,位于提供者部分,如下所示
... // Add this line $app->register(Kaysonwu\Flysystem\Aliyun\OssServiceProvider::class);
Laravel/Lumen配置
将适配器配置添加到config/filesystems.php
配置文件中的disks
数组中,如下所示
'disks' => [ ... 'aliyun-oss' => [ 'driver' => 'aliyun-oss', /** * The AccessKeyId from OSS or STS. */ 'key' => '<your AccessKeyId>', /** * The AccessKeySecret from OSS or STS */ 'secret' => '<your AccessKeySecret>', /** * The domain name of the datacenter. * * @example: oss-cn-hangzhou.aliyuncs.com */ 'endpoint' => '<endpoint address>', /** * The bucket name for the OSS. */ 'bucket' => '<bucket name>', /** * The security token from STS. */ 'token' => null, /** * If this is the CName and binded in the bucket. * * Values: true or false */ 'cname' => false, /** * Path prefix */ 'prefix' => '', /** * Request header options. * * @example [x-oss-server-side-encryption => 'KMS'] */ 'options' => [] ] ]
使用
基础
请参阅filesystem-api。
use Kaysonwu\Flysystem\Aliyun\OssAdapter; use League\Flysystem\Filesystem; use OSS\OssClient; $client = new OssClient( '<your AccessKeyId>', '<your AccessKeySecret>', '<endpoint address>' ); $adapter = new OssAdapter($client, '<bucket name>', 'optional-prefix', 'optional-options'); $filesystem = new Filesystem($adapter); $filesystem->has('file.txt'); // Dynamic call SDK method. $adapter->setTimeout(30); $filesystem->getAdapter()->setTimeout(30);
Laravel/Lumen
请参阅filesystem。
use Illuminate\Support\Facades\Storage; Storage::disk('aliyun-oss')->get('path'); // Dynamic call SDK method. Storage::disk('aliyun-oss')->getAdapter()->setTimeout(30);