Git Product home page Git Product logo

l5-gcs's Introduction

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

l5-gcs's People

Contributors

mix5003 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

rexchoppers

l5-gcs's Issues

Auto discovery

I can provide an update of this package with Laravel auto discovery if this is appreciated? Nice work on the package. Clean, simple and works better for me that the larger (more known) packages.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.