websight / l5-google-cloud-storage
Laravel 5 Flysystem Google Cloud Storage Service Provider
Installs: 60 746
Dependents: 0
Suggesters: 0
Security: 0
Stars: 36
Watchers: 4
Forks: 17
Open Issues: 7
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-11-09 19:23:35 UTC
README
Wraps cedricziel/flysystem-gcs in a Laravel 5.x compatible Service Provider.
Note:
This project doesn't support the deprecated p12
credentials format anymore.
If you rely on it, please use the 1.x
versions.
Configuration
Dedicated credentials: Obtain json service account credentials of a dedicated CloudPlatform Service Account
or
Local authentication through gcloud: Log in locally on your machine through the gcloud
command-line
utility.
-
Add the service provider to your application in
config/app.php
Websight\GcsProvider\CloudStorageServiceProvider::class,
-
Add a disk to the
disks
array in config/filesystems.php'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', ],
-
If Google Cloud Storage is the only
cloud
disk, you may consider setting it as thecloud
disk, so that you can access it likeStorage::cloud()->$operation()
via'cloud' => 'gcs',
in thefilesystems.php
config file.
Authentication and the different configuration options
Google Cloud Platform uses json credential files. For the use-case of this library, there are two different types that can easily confuse you.
- credentials type
user
This is the type of credentials that identifies you as a user entity, most likely when authenticated through thegcloud
utility. Since this type of credentials identifies users and users can belong to more than one project, you need to specify theproject_id
config option. The keys should automatically be detected through their well-known location. - credentials type
service_account
Service Account credentials are for authorizing machines and / or individual services to Google Cloud Platform. AppEngine instances and GCE machines already have a service account pre-installed so you don't need to configure neitherproject_id
notcredentials
, since service accounts carry the information to which project they belong.
When do I need to configure which option?
Usage
Use it like any other Flysystem Adapter with the 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');
License
MIT