我创建了自定义文件系统服务提供商来设置我的谷歌云存储。我有多个存储桶,所以我在 filesystems.php 中创建了多个磁盘。但由于所有这些存储桶都使用类似的设置,我想使用单个服务提供商。我们能做到吗?
服务提供者启动()
Storage::extend('gcs_images_1', function ($app, $config) {
$client = new StorageClient([
'projectId' => $config['project_id'],
'keyFilePath' => storage_path($config['key_file'])
]);
$bucket = $client->bucket($config['bucket']);
$pathPrefix = array_get($config, 'path_prefix');
$storageApiUri = array_get($config, 'storage_api_uri');
$adapter = new GoogleStorageAdapter($client, $bucket, $pathPrefix, $storageApiUri);
return new Filesystem($adapter);
});
配置/文件系统.php
'gcs_images_1' => [
'driver' => 'gcs_images_1',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'),
'key_file' => env('GOOGLE_CLOUD_KEY_FILE'),
'bucket' => 'img',
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null),
'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null)
],
'gcs_docs_1' => [
'driver' => 'gcs_docs_1',
'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'),
'key_file' => env('GOOGLE_CLOUD_KEY_FILE'),
'bucket' => 'doc',
'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', null),
'storage_api_uri' => env('GOOGLE_CLOUD_STORAGE_API_URI', null)
],