mirror of
https://gitee.com/ulthon/ulthon_admin.git
synced 2026-08-30 12:45:32 +08:00
feat(storage): 新增S3存储驱动与磁盘配置
This commit is contained in:
40
extend/think/filesystem/driver/S3.php
Normal file
40
extend/think/filesystem/driver/S3.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace think\filesystem\driver;
|
||||
|
||||
use Aws\S3\S3Client;
|
||||
use League\Flysystem\AwsS3V3\AwsS3V3Adapter;
|
||||
use League\Flysystem\FilesystemAdapter;
|
||||
use think\filesystem\Driver;
|
||||
|
||||
class S3 extends Driver
|
||||
{
|
||||
protected function createAdapter(): FilesystemAdapter
|
||||
{
|
||||
$options = [
|
||||
'version' => 'latest',
|
||||
'region' => sysconfig('upload', 's3_region'),
|
||||
'credentials' => [
|
||||
'key' => sysconfig('upload', 's3_access_key'),
|
||||
'secret' => sysconfig('upload', 's3_secret_key'),
|
||||
],
|
||||
];
|
||||
|
||||
$endpoint = sysconfig('upload', 's3_endpoint');
|
||||
if (!empty($endpoint)) {
|
||||
$options['endpoint'] = $endpoint;
|
||||
if (sysconfig('upload', 's3_path_style') === '1') {
|
||||
$options['use_path_style_endpoint'] = true;
|
||||
}
|
||||
}
|
||||
|
||||
$client = new S3Client($options);
|
||||
|
||||
return new AwsS3V3Adapter($client, sysconfig('upload', 's3_bucket'));
|
||||
}
|
||||
|
||||
public function url(string $path): string
|
||||
{
|
||||
return $this->concatPathToUrl(sysconfig('upload', 's3_domain'), $path);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user