2

I have installed composer require nao-pon/flysystem-google-drive:~1.1 on my project's root. I have also added this on my 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'),
    ]

Moreover, in my .env

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

And finally, in my app.php

App\Providers\GoogleDriveServiceProvider::class,

And even though I have all set up, it still gives me this error when I try to use this route

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

I get the error "Driver [google] is not supported."

Edited:

I have this on my GoogleDriveServiceProvider

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

/**
 * Bootstrap services.
 *
 * @return void
 */
public function boot()
{
    //
}
}
  • what is in this `GoogleDriveServiceProvider`? you would need to call `extend` on `Storage` some where to add the driver – lagbox Jul 12 '21 at 13:59

1 Answers1

0

Just adding the Flysystem driver for Google Drive doesn't make it available to Laravel's storage API. You need to either find an existing wrapper for it or extend it yourself.

For reference, this is the example they provide in the documentation for integrating with Dropbox (copied here rather than linked to in order to guard against link rot):

<?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));
        });
    }
}

Your implementation in App\Providers\GoogleDriveServiceProvider will need to call Storage::extend() in a similar fashion, and return an instance of Filesystem that wraps the Google Drive adapter for Flysystem.

Matthew Daly
  • 9,212
  • 2
  • 42
  • 83