我已經創建了自定義文件系統服務提供程序來設置我的谷歌雲存儲。我有多個桶,所以我在filesystems.php中創建了多個磁盤。但由於所有這些存儲桶都使用類似的設置,我想使用單個服務提供商。我們能做到嗎?自定義文件系統提供程序服務多個磁盤
ServicePrivider引導()
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);
});
配置/ filesystems.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)
],