嗨,我正在尝试将 google drive api 链接到 laravel 系统,因为我在 laravel 中使用了 google drive api 并配置了文件系统和 env 设置。但是在执行时它会返回 DISK not configured 错误。
尝试清除配置缓存和转储自动加载的解决方案仍然存在相同的问题。
文件系统.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_ACCESS_KEY_ID'),
'secret' => env('AWS_SECRET_ACCESS_KEY'),
'region' => env('AWS_DEFAULT_REGION'),
'bucket' => env('AWS_BUCKET'),
'url' => env('AWS_URL'),
],
'google-drive' => [
'driver' => 'google',
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
'folderId' => env('GOOGLE_DRIVE_FOLDER_ID'),
],
],
googledriveserviceprovider.php
public function boot()
{
Storage::extend('google-drive', function($app, $config) {
$client = new \Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$client->fetchAccessTokenWithRefreshToken($config['refreshToken']);
$service = new \Google_Service_Drive($client);
$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, $config['folderId']);
return new \League\Flysystem\Filesystem($adapter);
});
}
放置文件的路径。
Route::get('put', function() {
Storage::disk('google-drive')->put('test.txt', 'Hello World');
return 'File was saved to Google Drive';
});
任何帮助都深表感谢。