2017 © Pedro Peláez
 

library l5-gcs

Laravel 5.5+ Flysystem Google Cloud Storage Service Provider

image

mix5003/l5-gcs

Laravel 5.5+ Flysystem Google Cloud Storage Service Provider

  • Saturday, May 12, 2018
  • by mix5003
  • Repository
  • 1 Watchers
  • 0 Stars
  • 175 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 3 Versions
  • 59 % Grown

The README.md

Archived:

You can use Google CLoud Storage by standard S3 Driver (see interoperability)., (*1)

Sample Config in filesystems.php, (*2)

        'gcs' => [
            'driver' => 's3',
            'key' => env('GCS_HMAC_KEY'),
            'secret' => env('GCS_HMAC_SECRET'),
            'region' => 'auto',
            'endpoint' => 'https://storage.googleapis.com/' . env('GCS_ATTACHMENT_BUCKET') . '/',
            'bucket' => env('GCS_ATTACHMENT_BUCKET'),
            'bucket_endpoint' => true,
            'options' => ['ACL' => 'project-private'], // see more https://cloud.google.com/storage/docs/access-control/lists#predefined-acl
        ],

Google Cloud Storage ServiceProvider for Laravel 5.5+

Just Wraps cedricziel/flysystem-gcs in a Laravel 5.5+ compatible Service Provider. and add some other functionality that I need., (*3)

Addition Feature for Laravel

  • Can use temporaryUrl method.
  • Can add metadata when write object.

Installation

composer require mix5003/l5-gcs, (*4)

Register the service provider in app.php, (*5)

'providers' => [
    // ...
    mix5003\GCSProvider\GoogleCloudStorageServiceProvider::class,
]

Add a new disk to your filesystems.php config, (*6)

'gcs' => [
    'driver' => 'gcs',
    'projectId' => env('GCS_PROJECT_ID'),
    'bucket' => env('GCS_BUCKET'),
    'keyFilePath' => storage_path(env('GCS_KEY_FILE')),
    'url' => env('GCS_CUSTOM_URL'), // optional: for custom url only
],

Usage

Use it like any other Flysystem Adapter with the Storage-Facade., (*7)

$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
);

// Put a public-accessible file with metadata on the 'gcs' disk which is a Google Cloud Storage bucket 
$disk->put(
    'test.png',
    file_get_contents(storage_path('app/test.png')),
    [
        'metadata' => [
            'contentDisposition' => 'attachment; filename=file.png',
            'contentType' => 'image/png',
        ],
        'visibility' => \Illuminate\Contracts\Filesystem\Filesystem::VISIBILITY_PUBLIC
    ]
);

// Retrieve a file
$file = $disk->get('test.png');

// Get a temporary url for 1 hour
$disk->temporaryUrl('test.png', time() + 3600);

// Get a temporary url for 1 hour with other options
// see other option: https://googlecloudplatform.github.io/google-cloud-php/#/docs/google-cloud/v0.45.1/storage/storageobject?method=signedUrl
$disk->temporaryUrl('test.pdf', time() + 3600, ['saveAsName' => 'file.png']);

License

MIT, (*8)

The Versions

12/05 2018

dev-master

9999999-dev

Laravel 5.5+ Flysystem Google Cloud Storage Service Provider

  Sources   Download

MIT

The Requires

 

by Sorrawut Kittikeereechaikun

laravel laravel5 flysystem gcs

12/05 2018

2.0.0

2.0.0.0

Laravel 5.5+ Flysystem Google Cloud Storage Service Provider

  Sources   Download

MIT

The Requires

 

by Sorrawut Kittikeereechaikun

laravel laravel5 flysystem gcs

25/11 2017

1.0.0

1.0.0.0

Laravel 5.5+ Flysystem Google Cloud Storage Service Provider

  Sources   Download

MIT

The Requires

 

by Sorrawut Kittikeereechaikun

laravel laravel5 flysystem gcs