modernmcguire/flysystem-google-drive 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

modernmcguire/flysystem-google-drive

Composer 安装命令:

composer require modernmcguire/flysystem-google-drive

包简介

Flysystem adapter for Google Drive

README 文档

README

Author Software License

Installation

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

Follow Google Docs to obtain your ClientId, ClientSecret & refreshToken in addition you can also check this easy-to-follow tutorial

  1. Add a google disk to your config/filesystems.php.
'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'),
		'teamDriveId' => env('GOOGLE_DRIVE_TEAM_DRIVE_ID'),
	],
]
  1. Create a new Service Provider (App\Providers\GoogleDriveServiceProvider.php) to contain all of the setup logic.
<?php

namespace App\Providers;

use Google_Client;
use Google_Service_Drive;
use League\Flysystem\Filesystem;
use App\Http\Livewire\GoogleDriveUI;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\ServiceProvider;
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;

class GoogleDriveServiceProvider extends ServiceProvider
{
	public function register()
	{
		//
	}

	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']);
			$service = new Google_Service_Drive($client);

			$options = [];
			if (isset($config['teamDriveId'])) {
				$options['teamDriveId'] = $config['teamDriveId'];
			}

			$options['additionalFetchField'] = 'thumbnailLink,contentHints,webContentLink,webViewLink,iconLink';

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

			if (isset($config['teamDriveId']) && ! empty($config['teamDriveId'])) {
				// Reset the pathPrefix and root back to your custom parent folder
				$adapter->setPathPrefix($config['folderId']);
				$adapter->root = $config['folderId'];
			}

			// if we want to implement Flysystem caching
			// $cacheStore = new \League\Flysystem\Cached\Storage\Memory();
			// $adapter = new \League\Flysystem\Cached\CachedAdapter($adapter, $cacheStore);
			// return new Filesystem($adapter);

			return new Filesystem($adapter);
		});
	}
}
  1. Add the service provider to your providers array in config/app.php
'providers' => [

	/* ... */

	/*
     * Application Service Providers...
     */
	App\Providers\AppServiceProvider::class,
	App\Providers\AuthServiceProvider::class,
	App\Providers\BladeServiceProvider::class,
	// App\Providers\BroadcastServiceProvider::class,
	App\Providers\EventServiceProvider::class,

	App\Providers\GoogleDriveServiceProvider::class,


]

Usage

You can also check This Example for a better understanding of how to use the library directly.

You can see below for the indirect usage utilizing the Laravel Filesystem.

// get folders and files beneath a parent folder
Storage::disk('google')->listContents('/', $recursive = true);

Storage::disk('google')->get($path);
Storage::disk('google')->put($path, 'Some contents');

Storage::disk('google')->download($path, $filename);

Storage::disk('google')->delete($path);
Storage::disk('google')->deleteDirectory($path);

Storage::disk('google')->makeDirectory($path . '/Some new folder');

Storage::disk('google')->copy($source, $destination);
Storage::disk('google')->move($source, $destination);

Storage::disk('google')->setVisibility($path, 'public');
Storage::disk('google')->setVisibility($path, 'private');

Tips

modernmcguire/flysystem-google-drive 适用场景与选型建议

modernmcguire/flysystem-google-drive 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.65k 次下载、GitHub Stars 达 1, 最近一次更新时间为 2022 年 02 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 modernmcguire/flysystem-google-drive 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 modernmcguire/flysystem-google-drive 我们能提供哪些服务?
定制开发 / 二次开发

基于 modernmcguire/flysystem-google-drive 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4.65k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 1
  • 点击次数: 15
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 1
  • Watchers: 0
  • Forks: 129
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-02-22