【问题标题】:Disk [google-drive] does not have a configured driver磁盘 [google-drive] 没有配置驱动程序
【发布时间】:2020-07-27 14:23:06
【问题描述】:

您好,我正在尝试将 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';
        });

非常感谢任何帮助。

【问题讨论】:

  • 哪行给你DISK not configured error
  • 路由部分返回错误
  • 你不是已经问过这个问题了吗?为什么要开一个新的,为什么不继续你现有的问题呢? stackoverflow.com/q/63112749/1841839
  • 是的,这里的问题结构良好。那边解释有点笨拙
  • 你有什么解决办法吗?

标签: laravel google-drive-api laravel-storage laravel-filesystem


【解决方案1】:

我认为这行:

Storage::extend('google-drive', function($app, $config) {

应该是

Storage::extend('google', function($app, $config) {

【讨论】:

  • 不,无论如何都没有帮助
【解决方案2】:

我认为这对你有用

文件系统.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';
        });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-10-01
    • 1970-01-01
    • 2020-07-12
    • 2011-04-26
    • 1970-01-01
    • 2013-07-26
    • 2021-11-12
    • 1970-01-01
    相关资源
    最近更新 更多