modernmcguire/flysystem-google-drive
Composer 安装命令:
composer require modernmcguire/flysystem-google-drive
包简介
Flysystem adapter for Google Drive
README 文档
README
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
- Add a
googledisk to yourconfig/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'), ], ]
- 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); }); } }
- 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 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 15
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-02-22