websight / l5-google-cloud-storage
Laravel 5 Flysystem Google Cloud Storage 服务提供者
v2.0.0
2018-03-23 08:09 UTC
Requires
- cedricziel/flysystem-gcs: ^1.0
- illuminate/filesystem: ~5.0.17|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*
- illuminate/support: ~5.0.17|5.1.*|5.2.*|5.3.*|5.4.*|5.5.*|5.6.*
Requires (Dev)
- phpunit/phpunit: ^6.5
Suggests
- laravel/lumen-framework: To test the Lumen bindings
This package is not auto-updated.
Last update: 2024-09-14 18:42:09 UTC
README
将 cedricziel/flysystem-gcs 封装在 Laravel 5.x 兼容的服务提供者中。
注意:此项目不再支持已弃用的 p12
凭据格式。如果您依赖它,请使用 1.x
版本。
配置
专用凭证:获取专用 CloudPlatform 服务账户的 json 服务账户凭证
或者
通过 gcloud 本地认证:通过 gcloud
命令行工具在您的计算机上本地登录。
-
将服务提供者添加到您的应用程序中的
config/app.php
Websight\GcsProvider\CloudStorageServiceProvider::class,
-
在
config/filesystems.php
中的disks
数组中添加一个磁盘'gcs' => [ // Select the Google Cloud Storage Disk 'driver' => 'gcs', // OPTIONAL: The location of the json service account certificate, see below // 'credentials' => storage_path('my-service-account-credentials.json'), // OPTIONAL: The GCP project id, see below // 'project_id' => 'my-project-id-4711', // The bucket you want this disk to point at 'bucket' => 'my-project-id-4711.appspot.com', ],
-
如果 Google Cloud Storage 是唯一的
cloud
磁盘,您可以考虑将其设置为cloud
磁盘,这样您就可以通过'cloud' => 'gcs',
在filesystems.php
配置文件中像Storage::cloud()->$operation()
一样访问它。
认证和不同的配置选项
Google Cloud Platform 使用 json 凭证文件。对于此库的使用案例,有两种不同类型,可能会让您感到困惑。
- 凭证类型
user
这是标识您作为用户实体的凭证类型,很可能是通过gcloud
工具认证时。由于此类凭证标识用户,并且用户可能属于多个项目,因此您需要指定project_id
配置选项。键应自动通过其知名位置检测到。 - 凭证类型
service_account
服务账户凭证用于授权机器和/或单个服务访问 Google Cloud Platform。AppEngine 实例和 GCE 机器已经预装了服务账户,因此您不需要配置project_id
和credentials
,因为服务账户携带了它们所属项目的信息。
何时需要配置哪个选项?
用法
像使用其他 Flysystem 适配器一样使用它,通过 Storage
-Facade。
$disk = Storage::disk('gcs'); // Put a private file on the 'gcs' disk which is a Google Cloud Storage bucket $disk->put('test.png', file_get_contents(storage_path('app/test.png'))); // Put a public-accessible file on the 'gcs' disk which is a Google Cloud Storage bucket $disk->put( 'test-public.png', file_get_contents(storage_path('app/test-public.png')), \Illuminate\Contracts\Filesystem\Filesystem::VISIBILITY_PUBLIC ); // Retrieve a file $file = $disk->get('test.png');
许可证
MIT