Laravel Google Cloud Storage

spatie/laravel-google-cloud-storage image

Laravel Google Cloud Storage stats

Downloads
2M
Stars
136
Open Issues
1
Forks
39

View on GitHub →

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_CREDENTIALS pointing 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.
spatie photo

We create open source, digital products and courses for the developer community

Cube

Laravel Newsletter

Join 40k+ other developers and never miss out on new tips, tutorials, and more.


Spatie Laravel Google Cloud Storage Related Articles

Laravel Mobile Pass: Generate Apple Wallet and Google Wallet Passes image

Laravel Mobile Pass: Generate Apple Wallet and Google Wallet Passes

Read article
Building a Sitemap in your Laravel app with the Spatie Sitemap image

Building a Sitemap in your Laravel app with the Spatie Sitemap

Read article
Laravel Google Chat Alerts image

Laravel Google Chat Alerts

Read article
Crawl and Index Your Website with Laravel Site Search image

Crawl and Index Your Website with Laravel Site Search

Read article
Laravel Google Fonts Package image

Laravel Google Fonts Package

Read article
Image Optimization With Spatie Laravel Image Optimizer image

Image Optimization With Spatie Laravel Image Optimizer

Read article
Shift logo

Shift

Running an old Laravel version? Instant, automated Laravel upgrades and code modernization to keep your applications fresh.

Shift
PhpStorm logo

PhpStorm

The go-to PHP IDE with extensive out-of-the-box support for Laravel and its ecosystem.

PhpStorm
DreamzTech logo

DreamzTech

Hire 6-10+ Yrs. experienced skilled Laravel Developers from DreamzTech. We ensure NDA protected, 100% quality delivery. Contact Us & Discuss Your Need.

DreamzTech
The Certification of Competence for Laravel logo

The Certification of Competence for Laravel

A community-driven, proctored assessment across 4 levels designed to validate real-world Laravel knowledge, from Junior to mastery-level Artisan. Official Vue.js, Official Nuxt, Angular, React, JS certifications also available.

The Certification of Competence for Laravel
Acquaint Softtech logo

Acquaint Softtech

Acquaint Softtech offers AI-ready Laravel developers who onboard in 48 hours at $3000/Month with no lengthy sales process and a 100 percent money-back guarantee.

Acquaint Softtech
Tinkerwell logo

Tinkerwell

The must-have code runner for Laravel developers. Tinker with AI, autocompletion and instant feedback on local and production environments.

Tinkerwell