feat(storage): 新增S3存储驱动与磁盘配置

This commit is contained in:
augushong
2026-08-20 22:12:41 +08:00
parent f01ecbe08e
commit 5cdfac0333
2 changed files with 47 additions and 0 deletions

View 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);
}
}