【问题标题】:Driver [google] is not supported不支持驱动程序 [google]
【发布时间】:2021-09-21 16:43:30
【问题描述】:

我已经安装了 composer require nao-pon/flysystem-google-drive:~1.1 在我项目的根目录上。我也在我的 filesystems.php 中添加了这个

'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'),
    ]

此外,在我的 .env 中

GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=null

最后,在我的 app.php 中

App\Providers\GoogleDriveServiceProvider::class,

即使我已经全部设置,当我尝试使用这条路线时它仍然给我这个错误

Route::get('/test1', function() {
Storage::disk('google')->put('test.txt', 'Hello World');
});

我收到错误消息“不支持驱动程序 [google]。”

已编辑:

我的 GoogleDriveServiceProvider 上有这个

class GoogleDriveServiceProvider extends ServiceProvider
{
/**
 * Register services.
 *
 * @return void
 */
public function register()
{
    //
}

/**
 * Bootstrap services.
 *
 * @return void
 */
public function boot()
{
    //
}
}

【问题讨论】:

  • GoogleDriveServiceProvider 中有什么内容?您需要在 Storage 上调用 extend 来添加驱动程序

标签: laravel google-drive-api service-provider


【解决方案1】:

仅添加 Google Drive 的 Flysystem 驱动程序并不能使其可用于 Laravel 的存储 API。您需要为其找到现有的包装器或自行扩展它。

作为参考,这是他们在与 Dropbox 集成的文档中提供的示例(在此处复制而不是链接到以防止链接失效):

<?php

namespace App\Providers;

use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use League\Flysystem\Filesystem;
use Spatie\Dropbox\Client as DropboxClient;
use Spatie\FlysystemDropbox\DropboxAdapter;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        Storage::extend('dropbox', function ($app, $config) {
            $client = new DropboxClient(
                $config['authorization_token']
            );

            return new Filesystem(new DropboxAdapter($client));
        });
    }
}

您在App\Providers\GoogleDriveServiceProvider 中的实现需要以类似的方式调用Storage::extend(),并返回一个封装了Flysystem 的Google Drive 适配器的Filesystem 实例。

【讨论】:

  • 您好,您是对的。此外,我还需要在项目的根目录上安装 composer require google/apiclient 。谢谢你的回答。
猜你喜欢
  • 2021-08-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2022-12-24
  • 2015-06-17
  • 2019-07-29
  • 2011-05-16
相关资源
最近更新 更多