PHPackages                             cedricziel/flysystem-gcs - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. cedricziel/flysystem-gcs

AbandonedArchivedLibrary[File &amp; Storage](/categories/file-storage)

cedricziel/flysystem-gcs
========================

Flysystem adapter for Google Cloud Storage (GCS) that uses gcloud-php

v2.1.1(5y ago)14107.5k↓22.2%4[1 issues](https://github.com/cedricziel/flysystem-gcs/issues)[1 PRs](https://github.com/cedricziel/flysystem-gcs/pulls)4MITPHPPHP &gt;=7.2

Since Aug 23Pushed 5y ago2 watchersCompare

[ Source](https://github.com/cedricziel/flysystem-gcs)[ Packagist](https://packagist.org/packages/cedricziel/flysystem-gcs)[ RSS](/packages/cedricziel-flysystem-gcs/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (3)DependenciesVersions (14)Used By (4)

flysystem-gcs - Flysystem Adapter for Google Cloud Storage
==========================================================

[](#flysystem-gcs---flysystem-adapter-for-google-cloud-storage)

[![build status](https://github.com/cedricziel/flysystem-gcs/workflows/PHP%20Composer/badge.svg)](https://github.com/cedricziel/flysystem-gcs/workflows/PHP%20Composer/badge.svg)

Flysystem Adapter for Google cloud storage using the gcloud PHP library

Installation
------------

[](#installation)

Using composer:

```
composer require cedricziel/flysystem-gcs

```

How-To
------

[](#how-to)

```
use CedricZiel\FlysystemGcs\GoogleCloudStorageAdapter;
use League\Flysystem\Filesystem;

$adapterOptions = [
    'projectId' => 'my-project-id',
    'bucket'    => 'my-project-bucket.appspot.com',
    'prefix'    => 'my-path-prefix/inside/the/bucket',
];
$adapter = new GoogleCloudStorageAdapter(null, $adapterOptions);

$filesystem = new Filesystem($adapter);
```

Authentication
--------------

[](#authentication)

This library utilizes the PHP library [`google/cloud`](https://github.com/GoogleCloudPlatform/google-cloud-php), which in turn uses [google/auth](https://github.com/google/google-auth-library-php).

Why is this important? It's important, because if you're authenticated locally, through the `gcloud` command-line utility, or running on a Google Cloud Platform VM, in many cases you are already authenticated, and you don't need to do anything at all, in regards to authentication.

For any other case, you will most probably want to export the environment variable `GOOGLE_APPLICATION_CREDENTIALS` with a value of the absolute path to your service account credentials that is authorized to use the `Storage: Full Access` oAuth2 scope, and you're all set.

All examples, including tests, make use of this behaviour.

If that's not what you want, you can create your own `StorageClient` object that's authenticated differently and pass it to the adapter class constructor as first argument.

Demo
----

[](#demo)

There's [a demo project](https://github.com/cedricziel/flysystem-gcs-demo) that shows simple operations in a file system manager.

Public URLs to StorageObjects
-----------------------------

[](#public-urls-to-storageobjects)

The Adapter ships with 2 different methods to generate public URLs:

- a flysystem plugin that exposes a `getUrl($path)` method on your `FilesystemInterface` instance
- a `getUrl($path)` method on the adapter itself to generate the URL

Read below to know when you will want to use the one or the other.

### Flysystem Plugin

[](#flysystem-plugin)

The standard way to generate public urls with this adapter would be to add a flysystem plugin to your `FilesystemInterface` instance.

The plugins **needs** a piece of configuration, telling it whether and which bucket to use in combination with the standard accessible `https://storage.googleapis.com/bucket/object.url`, or with a custom [CNAME URL](https://cloud.google.com/storage/docs/xml-api/reference-uris#cname)such as `http://storage.my-domain.com`.

Notice that GCS public access via CNAMEs is `http` only (no `https`).

**Example: Standard public URL to bucket**

Supposed you have a bucket `my-application-bucket`, configure the plugin as follows:

```
// create your adapter as usual
$adapter = new GoogleCloudStorageAdapter(..);
// add it to your `FilesystemInterface` instance
$filesystem = new Filesystem($adapter);

// create your configuration
$path = 'text-object.txt';
$config = ['bucket' => 'my-application-bucket'];
$filesystem->addPlugin(new GoogleCloudStoragePublicUrlPlugin($config));
$publicUrl = $filesystem->getUrl($path);

// $publicUrl == 'https://storage.googleapis.com/my-application-bucket/text-object.txt';
```

**Example: Standard public URL to bucket with directory prefix**

Supposed you have a bucket `my-application-bucket` with a directory prefix of `my/prefix`, append the prefix separated by a slash to the bucket name:

```
// create your adapter as usual
$adapter = new GoogleCloudStorageAdapter(null, ['prefix' => 'my/prefix', ...]);
// add it to your `FilesystemInterface` instance
$filesystem = new Filesystem($adapter);

// create your configuration
$path = 'text-object.txt';
$config = ['bucket' => 'my-application-bucket/my/prefix'];
$filesystem->addPlugin(new GoogleCloudStoragePublicUrlPlugin($config));
$publicUrl = $filesystem->getUrl($path);

// $publicUrl == 'https://storage.googleapis.com/my-application-bucket/my/prefix/text-object.txt';
```

**Example: Custom domain to bucket**

Supposed you have setup a CNAME `assets.example.com` pointing to the public endpoint mentioned in the [documentation](https://cloud.google.com/storage/docs/xml-api/reference-uris#cname), you would configure the plugin as follows:

```
// create your adapter as usual
$adapter = new GoogleCloudStorageAdapter(..);
// add it to your `FilesystemInterface` instance
$filesystem = new Filesystem($adapter);

// create your configuration
$path = 'text-object.txt';
$config = ['url' => 'http://assets.example.com'];
$filesystem->addPlugin(new GoogleCloudStoragePublicUrlPlugin($config));
$publicUrl = $filesystem->getUrl($path);

// $publicUrl == 'http://assets.example.com/text-object.txt'
```

**Example: Custom domain to bucket with directory prefix**

Supposed you have setup a CNAME `assets.example.com` pointing to the public endpoint mentioned in the [documentation](https://cloud.google.com/storage/docs/xml-api/reference-uris#cname), and your filesystem uses a directory prefix of `my/prefix` you need to append the prefix to the `url` in the configuration and would configure the plugin as follows:

```
// create your adapter as usual
$adapter = new GoogleCloudStorageAdapter(null, ['prefix' => 'my/prefix', ...]);
// add it to your `FilesystemInterface` instance
$filesystem = new Filesystem($adapter);

// create your configuration
$path = 'text-object.txt';
$config = ['url' => 'http://assets.example.com/my/prefix'];
$filesystem->addPlugin(new GoogleCloudStoragePublicUrlPlugin($config));
$publicUrl = $filesystem->getUrl($path);

// $publicUrl == 'http://assets.example.com/my/prefix/text-object.txt'
```

### `getUrl` on the adapter / Laravel 5

[](#geturl-on-the-adapter--laravel-5)

The Storage services used in Laravel 5 do not use flysystem plugins.

The Laravel 5 specific flysystem instance checks if there's a `getUrl`method on the adapter object.

This method is implemented on the Adapter, which is why you can add the adapter directly and use it right away:

```
// create the adapter
Storage::extend('gcs', function($app, $config) {
    $adapter = new GoogleCloudStorageAdapter(null, ['bucket' => 'my-bucket', ...]);
    // add it to your `FilesystemInterface` instance
    return new Filesystem($adapter);
});

// register a new disk of type 'gcs' and name it 'gcs'

// use it
$gcs = Storage::disk('gcs');
$path = 'test-laravel.txt';
$gcs->put($path, 'test-content', AdapterInterface::VISIBILITY_PUBLIC);

$publicUrl = $gcs->url($path);
// $publicUrl == 'https://storage.googleapis.com/my-application-bucket/test-laravel.txt';
```

Development
-----------

[](#development)

Some tests require actual access to GCS. They can be configured through the environment.

variablemeaningGOOGLE\_APPLICATION\_CREDENTIALSabsolute path to the service account credentials \*.json fileGOOGLE\_CLOUD\_BUCKETname of the GCS bucket to perform the tests onGOOGLE\_CLOUD\_PROJECTthe cloud project id to useCode Style
----------

[](#code-style)

You can use PHP-CS-Fixer to format the code:

```
# install fixer
$ composer install --working-dir=tools/php-cs-fixer

# execute fixer
$ tools/php-cs-fixer/vendor/bin/php-cs-fixer fix --allow-risky=yes

```

License
-------

[](#license)

MIT

###  Health Score

39

—

LowBetter than 86% of packages

Maintenance19

Infrequent updates — may be unmaintained

Popularity38

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity65

Established project with proven stability

 Bus Factor1

Top contributor holds 96.8% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~147 days

Recently: every ~265 days

Total

12

Last Release

1931d ago

Major Versions

v0.3.0 → v1.0.02016-09-10

v1.1.0 → v2.0.02018-01-28

PHP version history (2 changes)v2.0.0PHP &gt;=7.0

v2.1.0PHP &gt;=7.2

### Community

Maintainers

![](https://www.gravatar.com/avatar/2ac8297e12671d91305ec01ab56add8cb141fa82d678ba96f0012eeb7f88ea0c?d=identicon)[cedricziel](/maintainers/cedricziel)

---

Top Contributors

[![cedricziel](https://avatars.githubusercontent.com/u/418970?v=4)](https://github.com/cedricziel "cedricziel (92 commits)")[![daohoangson](https://avatars.githubusercontent.com/u/239336?v=4)](https://github.com/daohoangson "daohoangson (2 commits)")[![emilv](https://avatars.githubusercontent.com/u/1684914?v=4)](https://github.com/emilv "emilv (1 commits)")

---

Tags

flysystem-adapterflysystem-plugingoogle-cloud-storagefilesystemFlysystemcloudgooglegcsgoogle cloud storage

### Embed Badge

![Health badge](/badges/cedricziel-flysystem-gcs/health.svg)

```
[![Health](https://phpackages.com/badges/cedricziel-flysystem-gcs/health.svg)](https://phpackages.com/packages/cedricziel-flysystem-gcs)
```

###  Alternatives

[league/flysystem

File storage abstraction for PHP

13.6k639.1M2.2k](/packages/league-flysystem)[google/cloud

Google Cloud Client Library

1.2k16.2M53](/packages/google-cloud)[league/flysystem-aws-s3-v3

AWS S3 filesystem adapter for Flysystem.

1.6k263.6M790](/packages/league-flysystem-aws-s3-v3)[league/flysystem-google-cloud-storage

Google Cloud Storage adapter for Flysystem.

2316.7M45](/packages/league-flysystem-google-cloud-storage)[league/flysystem-local

Local filesystem adapter for Flysystem.

225231.8M39](/packages/league-flysystem-local)[oneup/flysystem-bundle

Integrates Flysystem filesystem abstraction library to your Symfony project.

64422.9M66](/packages/oneup-flysystem-bundle)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
