ivanvermeyen / laravel-google-drive-demo

Laravel & Google Drive Storage - Demo project with Laravel 5.4
405 stars 155 forks source link

Added optional support for Google Team Drives #36

Closed tobias-kuendig closed 6 years ago

tobias-kuendig commented 6 years ago

This PR adds support for storing files on Team Drives.

ivanvermeyen commented 6 years ago

I can't verify if this works, but I will gladly take your word for it. Thanks for the contribution 👍

tobias-kuendig commented 6 years ago

Great! I had to upload files to a Team Drive and came across your example repo.

There is a problem with the current flysystem adapter that only allows files to be uploaded to the root directory of a team drive.

A PR with the fix got merged. Until a new version is released a temporary solution is to add the following lines before the return statement of the GoogleDriveServiceProvider:

\Storage::extend('google', function($app, $config) {
    $client = new \Google_Client();
    $client->setClientId($config['clientId']);
    $client->setClientSecret($config['clientSecret']);
    $client->refreshToken($config['refreshToken']);

    $service = new \Google_Service_Drive($client);

    $adapter = new GoogleDriveAdapter($service, $config['folderId'], ['teamDriveId' => $config['teamDriveId']]);

    // Reset the pathPrefix and root back to your custom parent folder
    $adapter->setPathPrefix($config['folderId']);
    $adapter->root = $config['folderId'];

    return new \League\Flysystem\Filesystem($adapter);
});
ivanvermeyen commented 6 years ago

Ok, I will do a composer update when the fix gets tagged, so the lock file of the demo is up to date.