Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Latest commit

 

History

History
90 lines (74 loc) · 2.92 KB

README.md

File metadata and controls

90 lines (74 loc) · 2.92 KB

Archived:

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

Sample Config in filesystems.php

        '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.

Addition Feature for Laravel

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

Installation

composer require mix5003/l5-gcs

Register the service provider in app.php

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

Add a new disk to your filesystems.php config

'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.

$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