您好,我正在尝试将google drive api链接到laravel系统,因为我在laravel中使用了google drive api,并配置了文件系统和环境设置。但在执行时,它会返回DISK not configured错误。
清除配置缓存和转储-自动加载的尝试解决方案仍然保持不变。
filesystem.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';
});任何帮助我们都深表感谢。
发布于 2020-07-27 22:34:51
我认为这句话:
Storage::extend('google-drive', function($app, $config) {应该就是这样
Storage::extend('google', function($app, $config) {发布于 2021-03-06 14:47:33
我认为这对你很有用
filesystem.php
'disks' => [
'google' => [
'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', 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')->put('test.txt', 'Hello World');
return 'File was saved to Google Drive';
});https://stackoverflow.com/questions/63117377
复制相似问题