Laravel Google Cloud Storage
Laravel Google Cloud Storage stats
- Downloads
- 2M
- Stars
- 136
- Open Issues
- 1
- Forks
- 39
Google Cloud Storage filesystem driver for Laravel
Google Cloud Storage Filesystem Driver for Laravel
This Laravel package, developed by Spatie, integrates Google Cloud Storage (GCS) with Laravel's filesystem, providing a seamless way to manage files in GCS using Laravel's native filesystem operations. The package is compatible with Laravel 9 and utilizes Flysystem v3 along with a specialized GCS adapter.
Key Features:
- Flexible Configuration: Configure with a JSON key file or directly through environment variables.
- Public and Signed URLs: Easily generate public and temporary signed URLs for accessing private files.
- Visibility Control: Supports setting default visibility and handling uniform bucket-level access.
- Extensive File Operations: Supports common operations like read, write, update, and delete alongside copying, moving, and more.
- Multi-Environment Support: Works on Google App Engine and Google Compute Engine, utilizing built-in service accounts.
Installation:
Install via composer:
composer require spatie/laravel-google-cloud-storage
Add a new disk configuration to filesystems.php:
'gcs' => [ 'driver' => 'gcs', 'key_file_path' => env('GOOGLE_CLOUD_KEY_FILE'), 'project_id' => env('GOOGLE_CLOUD_PROJECT_ID'), 'bucket' => env('GOOGLE_CLOUD_STORAGE_BUCKET'), 'path_prefix' => env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX'), 'visibility' => 'public', 'metadata' => ['cacheControl' => 'public,max-age=86400'],],
Usage Examples:
$disk = Storage::disk('gcs');$disk->put('avatars/1', $fileContents);$url = $disk->url('folder/my_file.txt');$disk->setVisibility('folder/my_file.txt', 'public');
Authentication Methods:
- Uses JSON credentials file specified in the disk configuration.
- Environment variable
GOOGLE_APPLICATION_CREDENTIALSpointing to the credentials file. - Automatically determines credentials when running in Google Cloud environments.
Generating URLs:
Handles both public and signed URLs, suitable for files with different visibility settings:
$url = $disk->temporaryUrl('folder/my_file.txt', now()->addMinutes(30));
Uniform Bucket-Level Access:
To handle permissions uniformly at the bucket level, configure the visibility_handler:
'visibility_handler' => \League\Flysystem\GoogleCloudStorage\UniformBucketLevelAccessVisibility::class,
Additional Information:
For full list of functionalities, refer to the Laravel filesystem documentation.
Testing:
Run tests using:
composer test
For contributing guidelines, security policies, and more details on changes, check the package's GitHub repository. This package is released under the MIT license.
Credits:
- Original GCS adapter by Superbalist.
- Maintained and enhanced by Alex Vanderbist and contributors from Spatie.