This is a Flysystem adapter for the Aliyun OSS ~2.3
$ composer require mocode/flysystem-aliyunoss
use League\Flysystem\Filesystem;
use Mocode\Flysystem\AliyunOss\AliyunOssAdapter;
use OSS\OssClient;
$accessId = 'Aliyun Oss Access Id';
$accessKey = 'Aliyun Oss Access Key';
$endPoint = 'Aliyun Oss endPoint';
$bucket = 'Aliyun Oss Bucket';
$domain = 'Aliyun Oss CDN Domain';
$client = new OssClient($accessId, $accessKey, $endPoint);
$adapter = new AliyunOssAdapter($client, $bucket, $domain);
$flysystem = new Filesystem($adapter);
bool $flysystem->write('file.md', 'contents');
bool $flysystem->writeStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool $flysystem->update('file.md', 'new contents');
bool $flysystem->updateStream('file.md', fopen('path/to/your/local/file.jpg', 'r'));
bool $flysystem->rename('foo.md', 'bar.md');
bool $flysystem->copy('foo.md', 'foo2.md');
bool $flysystem->delete('file.md');
bool $flysystem->has('file.md');
string|false $flysystem->read('file.md');
array $flysystem->listContents();
array $flysystem->getMetadata('file.md');
int $flysystem->getSize('file.md');
string $flysystem->getAdapter()->getUrl('file.md');
string $flysystem->getMimetype('file.md');
int $flysystem->getTimestamp('file.md');
File Url:
use Mocode\Flysystem\AliyunOss\\Plugins\PutFile;
$flysystem->addPlugin(new PutFile());
bool $flysystem->putFile('file.md', 'contents');
edit .env
add aliyun oss config
OSS_ACCESS_ID=xxxxxxxxxxxx
OSS_ACCESS_KEY=xxxxxxxxxxxxxxxxxxxxxx
OSS_BUCKET=xxxxxxxxxx
OSS_ENDPOINT=xxxxxxxxx
OSS_DOMAIN=xxxxxxxxxxxx
edit the config file: config/filesystems.php
add config
'oss' => [
'driver' => 'oss',
'access_id' => env('OSS_ACCESS_ID'), // Aliyun OSS AccessKeyId
'access_key' => env('OSS_ACCESS_KEY'), // Aliyun OSS AccessKeySecret
'bucket' => env('OSS_BUCKET'), // OSS bucket name
'endpoint' => env('OSS_ENDPOINT'), // OSS 节点或自定义外部域名
'domain' => env('OSS_DOMAIN'), // CDN domain
],
change default to oss
'default' => 'oss'
see Laravel wiki
MIT