首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >磁盘[google-drive]没有配置的驱动程序

磁盘[google-drive]没有配置的驱动程序
EN

Stack Overflow用户
提问于 2020-07-27 22:23:07
回答 2查看 878关注 0票数 0

您好,我正在尝试将google drive api链接到laravel系统,因为我在laravel中使用了google drive api,并配置了文件系统和环境设置。但在执行时,它会返回DISK not configured错误。

清除配置缓存和转储-自动加载的尝试解决方案仍然保持不变。

filesystem.php

代码语言:javascript
复制
'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

代码语言:javascript
复制
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);
        }); 
        
    }

上传文件的路径。

代码语言:javascript
复制
Route::get('put', function() {
            Storage::disk('google-drive')->put('test.txt', 'Hello World');
            return 'File was saved to Google Drive';
        });

任何帮助我们都深表感谢。

EN

回答 2

Stack Overflow用户

发布于 2020-07-27 22:34:51

我认为这句话:

代码语言:javascript
复制
Storage::extend('google-drive', function($app, $config) {

应该就是这样

代码语言:javascript
复制
Storage::extend('google', function($app, $config) {
票数 0
EN

Stack Overflow用户

发布于 2021-03-06 14:47:33

我认为这对你很有用

filesystem.php

代码语言:javascript
复制
'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

代码语言:javascript
复制
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);
        }); 
        
    }

路由文件

代码语言:javascript
复制
Route::get('put', function() {
            Storage::disk('google')->put('test.txt', 'Hello World');
            return 'File was saved to Google Drive';
        });
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/63117377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档