Skip to content
Flysystem adapter for Google Drive
PHP
Branch: master
Clone or download
DynamoGeek and nao-pon Fixes a (very unlikely to be hit) bug that'll cause a failure to up… (#…
…55)

* - Fixes a (very unlikely to be hit) bug that'll cause a failure to upload if the passed in resource is the exact same length as the chunk size
- Fixes a bug where chunk size wasn't being detected as a multiple of 262,144B (256KB), causing a failure to upload
- Fixes a bug where out of memory errors are likely when working with larger files due to chunk size being based on the memory limit, rather than the remaining available memory

* Updated the order of variables in a method call to be correct.

* Updated to move $client->setDefer(true) before create/update of the Drive file to prevent a fatal error.

* correction to use `setDefer(true)` and chunk size

After all, using `getFileObject ()` after using `setDefer (true)` make a problem, so I fixed. In addition, the calculation method of the chunk size is also corrected. This commit solves all problems I know of.
Latest commit b99f4f8 May 3, 2019
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
example add an example + update rdme Sep 22, 2016
src Fixes a (very unlikely to be hit) bug that'll cause a failure to up… (#… May 3, 2019
tests Fixes a (very unlikely to be hit) bug that'll cause a failure to up… (#… May 3, 2019
.gitignore update .gitignore Feb 9, 2019
.scrutinizer.yml first commit Feb 6, 2016
.travis.yml first commit Feb 6, 2016
LICENSE first commit Feb 6, 2016
README.md Update README.md (#32) Apr 24, 2018
changelog.md first commit Feb 6, 2016
composer.json require google/apiclient : ^2.0 Jun 8, 2016
phpunit.hhvm.xml
phpunit.php first commit Feb 6, 2016
phpunit.xml first commit Feb 6, 2016

README.md

Flysystem Adapter for Google Drive

Author Software License

Installation

  • For Google Drive API V3
composer require nao-pon/flysystem-google-drive:~1.1
  • For Google Drive API V2 "Deprecated"
composer require nao-pon/flysystem-google-drive:~1.0.0

Usage

follow Google Docs to obtain your ClientId, ClientSecret & refreshToken

  • you can also check This Example for a better understanding.
$client = new \Google_Client();
$client->setClientId('[app client id].apps.googleusercontent.com');
$client->setClientSecret('[app client secret]');
$client->refreshToken('[your refresh token]');

$service = new \Google_Service_Drive($client);

$adapter = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, '['root' or folder ID]');
/* Recommended cached adapter use */
// $adapter = new \League\Flysystem\Cached\CachedAdapter(
//     new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter($service, '['root' or folder ID]'),
//     new \League\Flysystem\Cached\Storage\Memory()
// );

$filesystem = new \League\Flysystem\Filesystem($adapter);

Usage to with elFinder

composer require nao-pon/elfinder-flysystem-driver-ext
composer require nao-pon/flysystem-google-drive:~1.1
// Load composer autoloader
require 'vender/autoload.php';

// Google API Client
$client = new \Google_Client();
$client->setClientId('xxxxx CLIENTID xxxxx');
$client->setClientSecret('xxxxx CLIENTSECRET xxxxx');
$client->refreshToken('xxxxx REFRESH TOKEN xxxxx');

// Google Drive Adapter
$googleDrive = new \Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter(
	new \Google_Service_Drive($client), // Client service
	'root',                             // Folder ID as root ('root' or Folder ID)
	[ 'useHasDir' => true ]             // options (elFinder need hasDir method)
);

// Extended cached strage adapter class for cache enabled of hasDir() method
class myCachedStrageAdapter extends \League\Flysystem\Cached\Storage\Adapter
{
    use \Hypweb\Flysystem\Cached\Extra\Hasdir;
    use \Hypweb\Flysystem\Cached\Extra\DisableEnsureParentDirectories;
}

// Make Flysystem adapter and cache object
$useCache = true;
if ($useCache) {
	// Example to Flysystem cacheing
	$cache = new myCachedStrageAdapter(
		new \League\Flysystem\Adapter\Local('flycache'),
		'gdcache',
		300
	);

	// Flysystem cached adapter
	$adapter = new \League\Flysystem\Cached\CachedAdapter(
		$googleDrive,
		$cache
	);
} else {
	// Not use cached adapter
	$cache = null;
	$adapter = $googleDrive;
}

// Google Drive elFinder Volume driver
$gdrive = [
    // require
    'driver'       => 'FlysystemExt',
    'filesystem'   =>  new \League\Flysystem\Filesystem($adapter),
    'fscache'      => $cache,
    'separator'    => '/',
    // optional
    'alias'        => 'GoogleDrive',
    'rootCssClass' => 'elfinder-navbar-root-googledrive'
];

// elFinder volume roots options
$elFinderOpts = [
	'roots' => []
];

$elFinderOpts['roots'][] = $gdrive;

// run elFinder
$connector = new elFinderConnector(new elFinder($elFinderOpts));
$connector->run();

Tips

TODO

  • Unit tests to be written
You can’t perform that action at this time.