Laravel 5 Flysystem Google Cloud Storage Service Provider
Wraps cedricziel/flysystem-gcs in a Laravel 5.x compatible Service Provider.
This project doesn't support the deprecated
p12 credentials format anymore.
If you rely on it, please use the
Dedicated credentials: Obtain json service account credentials of a dedicated CloudPlatform Service Account
Local authentication through gcloud: Log in locally on your machine through the
Add the service provider to your application in
Add a disk to the
disksarray 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
clouddisk, you may consider setting it as the
clouddisk, so that you can access it like
'cloud' => 'gcs',in the
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
userThis is the type of credentials that identifies you as a user entity, most likely when authenticated through the
gcloudutility. Since this type of credentials identifies users and users can belong to more than one project, you need to specify the
project_idconfig option. The keys should automatically be detected through their well-known location.
- credentials type
service_accountService 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 neither
credentials, since service accounts carry the information to which project they belong.
|AppEngine (Standard & Flex)||detected automatically||detected automatically||needs to be set|
|Deployment to non-GCP machine||needs to be set||needs to be set||needs to be set|
|Local development with user credentials||needs to be set||detected automatically||needs to be set|
|Local development with service account||detected automatically||needs to be set||needs to be set|
Use it like any other Flysystem Adapter with the
$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');