我已经在项目的根目录下安装了composer require nao-pon/flysystem-google-drive:~1.1。我还在我的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'),
]此外,在我的.env中
GOOGLE_DRIVE_CLIENT_ID=xxx.apps.googleusercontent.com
GOOGLE_DRIVE_CLIENT_SECRET=xxx
GOOGLE_DRIVE_REFRESH_TOKEN=xxx
GOOGLE_DRIVE_FOLDER_ID=null最后,在我的app.php中
App\Providers\GoogleDriveServiceProvider::class,即使我已经全部设置好了,当我尝试使用这个路由时,它仍然会给我这个错误
Route::get('/test1', function() {
Storage::disk('google')->put('test.txt', 'Hello World');
});我得到的错误是“驱动程序google不受支持”。
编辑:
我的GoogleDriveServiceProvider上有这个
class GoogleDriveServiceProvider extends ServiceProvider
{
/**
* Register services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap services.
*
* @return void
*/
public function boot()
{
//
}
}发布于 2021-07-12 22:05:34
仅仅为Google Drive添加Flysystem驱动程序并不能使其可用于Laravel的存储API。您需要为它找到现有的包装器,或者自己扩展它。
作为参考,这是他们在文档中提供的与Dropbox集成的示例(复制到此处而不是链接到此处,以防止链接损坏):
<?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));
});
}
}您在App\Providers\GoogleDriveServiceProvider中的实现将需要以类似的方式调用Storage::extend(),并返回一个包装了Google Drive适配器for Flysystem的Filesystem实例。
https://stackoverflow.com/questions/68348667
复制相似问题