{"id":19324941,"url":"https://github.com/spatie/laravel-google-cloud-storage","last_synced_at":"2025-05-14T17:09:12.249Z","repository":{"id":39732835,"uuid":"390024676","full_name":"spatie/laravel-google-cloud-storage","owner":"spatie","description":"Google Cloud Storage filesystem driver for Laravel","archived":false,"fork":false,"pushed_at":"2025-03-13T09:57:16.000Z","size":104,"stargazers_count":211,"open_issues_count":0,"forks_count":56,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-08T09:02:11.524Z","etag":null,"topics":["google","google-cloud-platform","laravel","php"],"latest_commit_sha":null,"homepage":"https://spatie.be/open-source","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2021-07-27T14:58:32.000Z","updated_at":"2025-04-04T04:40:53.000Z","dependencies_parsed_at":"2025-03-25T07:00:24.947Z","dependency_job_id":"4ae2ea99-26fa-4fa6-ae18-d53952feddc2","html_url":"https://github.com/spatie/laravel-google-cloud-storage","commit_stats":{"total_commits":89,"total_committers":23,"mean_commits":3.869565217391304,"dds":0.7640449438202247,"last_synced_commit":"cb1f33be6824190cb9889c39712f5d4cd382f218"},"previous_names":[],"tags_count":22,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-google-cloud-storage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-google-cloud-storage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-google-cloud-storage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-google-cloud-storage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-google-cloud-storage/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254190396,"owners_count":22029632,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["google","google-cloud-platform","laravel","php"],"created_at":"2024-11-10T02:07:37.432Z","updated_at":"2025-05-14T17:09:12.228Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Google Cloud Storage filesystem driver for Laravel\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-google-cloud-storage.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-google-cloud-storage)\n[![run-tests](https://github.com/spatie/laravel-google-cloud-storage/actions/workflows/run-tests.yml/badge.svg)](https://github.com/spatie/laravel-google-cloud-storage/actions/workflows/run-tests.yml)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-google-cloud-storage.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-google-cloud-storage)\n\n---\n\nGoogle Cloud Storage filesystem driver for Laravel 9 and above (using Flysystem v3 and its own GCS adapter).\n\n**Looking for Laravel 8 support? Use the `v1` branch!**\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-google-cloud-storage.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-google-cloud-storage)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-google-cloud-storage\n```\n\nNext, add a new disk to your `filesystems.php` config:\n\n```php\n'gcs' =\u003e [\n    'driver' =\u003e 'gcs',\n    'key_file_path' =\u003e env('GOOGLE_CLOUD_KEY_FILE', null), // optional: /path/to/service-account.json\n    'key_file' =\u003e [], // optional: Array of data that substitutes the .json file (see below)\n    'project_id' =\u003e env('GOOGLE_CLOUD_PROJECT_ID', 'your-project-id'), // optional: is included in key file\n    'bucket' =\u003e env('GOOGLE_CLOUD_STORAGE_BUCKET', 'your-bucket'),\n    'path_prefix' =\u003e env('GOOGLE_CLOUD_STORAGE_PATH_PREFIX', ''), // optional: /default/path/to/apply/in/bucket\n    'storage_api_uri' =\u003e env('GOOGLE_CLOUD_STORAGE_API_URI', null), // see: Public URLs below\n    'api_endpoint' =\u003e env('GOOGLE_CLOUD_STORAGE_API_ENDPOINT', null), // set storageClient apiEndpoint\n    'visibility' =\u003e 'public', // optional: public|private\n    'visibility_handler' =\u003e null, // optional: set to \\League\\Flysystem\\GoogleCloudStorage\\UniformBucketLevelAccessVisibility::class to enable uniform bucket level access\n    'metadata' =\u003e ['cacheControl' =\u003e 'public,max-age=86400'], // optional: default metadata\n],\n```\n\n## Usage\n\n```php\n$disk = Storage::disk('gcs');\n\n$disk-\u003eput('avatars/1', $fileContents);\n$exists = $disk-\u003eexists('file.jpg');\n$time = $disk-\u003elastModified('file1.jpg');\n$disk-\u003ecopy('old/file1.jpg', 'new/file1.jpg');\n$disk-\u003emove('old/file1.jpg', 'new/file1.jpg');\n$url = $disk-\u003eurl('folder/my_file.txt');\n$url = $disk-\u003etemporaryUrl('folder/my_file.txt', now()-\u003eaddMinutes(30));\n$disk-\u003esetVisibility('folder/my_file.txt', 'public');\n```\n\nSee https://laravel.com/docs/master/filesystem for full list of available functionality.\n\n### Authentication\n\nThe Google Client uses a few methods to determine how it should authenticate with the Google API.\n\n1. If you specify a path in the key `key_file_path` in  disk config, that json credentials file will be used.\n2. If the `GOOGLE_APPLICATION_CREDENTIALS` env var is set, it will use that.\n   ```php\n   putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json');\n   ```\n3. It will then try load the key file from a 'well known path':\n    * windows: %APPDATA%/gcloud/application_default_credentials.json\n    * others: $HOME/.config/gcloud/application_default_credentials.json\n\n4. If running in **Google App Engine**, the built-in service account associated with the application will be used.\n5. If running in **Google Compute Engine**, the built-in service account associated with the virtual machine instance will be used.\n6. If you want to authenticate directly without using a json file, you can specify an array for `key_file` in disk config with this data:\n    ```php\n    'key_file' =\u003e [\n        'type' =\u003e env('GOOGLE_CLOUD_ACCOUNT_TYPE'),\n        'private_key_id' =\u003e env('GOOGLE_CLOUD_PRIVATE_KEY_ID'),\n        'private_key' =\u003e env('GOOGLE_CLOUD_PRIVATE_KEY'),\n        'client_email' =\u003e env('GOOGLE_CLOUD_CLIENT_EMAIL'),\n        'client_id' =\u003e env('GOOGLE_CLOUD_CLIENT_ID'),\n        'auth_uri' =\u003e env('GOOGLE_CLOUD_AUTH_URI'),\n        'token_uri' =\u003e env('GOOGLE_CLOUD_TOKEN_URI'),\n        'auth_provider_x509_cert_url' =\u003e env('GOOGLE_CLOUD_AUTH_PROVIDER_CERT_URL'),\n        'client_x509_cert_url' =\u003e env('GOOGLE_CLOUD_CLIENT_CERT_URL'),\n    ],\n    ```\n\n### Public URLs\n\nThe adapter implements a `getUrl($path)` method which returns a public url to a file.\n\u003e**Note:** Method available for Laravel 5.2 and higher. If used on 5.1, it will throw an exception.\n\n```php\n$disk = Storage::disk('gcs');\n$url = $disk-\u003eurl('folder/my_file.txt');\n// http://storage.googleapis.com/bucket-name/folder/my_file.txt\n```\n\nIf you configure a `path_prefix` in your config:\n```php\n$disk = Storage::disk('gcs');\n$url = $disk-\u003eurl('folder/my_file.txt');\n// http://storage.googleapis.com/bucket-name/path-prefix/folder/my_file.txt\n```\n\nIf you configure a custom `storage_api_uri` in your config:\n```php\n$disk = Storage::disk('gcs');\n$url = $disk-\u003eurl('folder/my_file.txt');\n// http://your-custom-domain.com/bucket-name/path-prefix/folder/my_file.txt\n```\n\nFor a custom domain (storage api uri), you will need to configure a CNAME DNS entry pointing to `storage.googleapis.com`.\n\nPlease see https://cloud.google.com/storage/docs/xml-api/reference-uris#cname for further instructions.\n\n### Temporary / Signed URLs\n\nWith the latest adapter versions, you can easily generate a signed URLs for files that are not publicly visible by default.\n\n```php\n$disk = Storage::disk('gcs');\n$url = $disk-\u003etemporaryUrl('folder/my_file.txt', now()-\u003eaddMinutes(30));\n// https://storage.googleapis.com/test-bucket/folder/my_file.txt?GoogleAccessId=test-bucket%40test-gcp.iam.gserviceaccount.com\u0026Expires=1571151576\u0026Signature=tvxN1OS1txkWAUF0cCR3FWK%seRZXtFu42%04%YZACYL2zFQxA%uwdGEmdO1KgsHR3vBF%I9KaEzPbl4b7ic2IWUuo8Jh3IoZFqdTQec3KypjDtt%02DGwm%OO6pWDVV421Yp4z520%o5oMqGBtV8B3XmjW2PH76P3uID2QY%AlFxn23oE9PBoM2wXr8pDXhMPwZNJ0FtckSc26O8PmfVsG7Jvln%CQTU57IFyB7JnNxz5tQpc2hPTHbCGrcxVPEISvdOamW3I%83OsXr5raaYYBPcuumDnAmrK%cyS9%Ky2fL2B2shFO2cz%KRu79DBPqtnP2Zf1mJWBTwxVUCK2jxEEYcXBXtdOszIvlI6%tp2XfVwYxLNFU\n```\n\n## Uniform bucket-level access\n\nGoogle Cloud Storage allows setting permissions at the bucket level i.e. \"Uniform bucket-level access\".\n\nInitially, the error \"Cannot insert legacy ACL for an object when uniform bucket-level access is enabled\" is observed.\n\nWhen uploading files to such buckets ensure the `visibility_handler` within the configuration file is set as follows:\n\n```php\n'visibility_handler' =\u003e \\League\\Flysystem\\GoogleCloudStorage\\UniformBucketLevelAccessVisibility::class,\n```\n\nPlease see https://cloud.google.com/storage/docs/access-control/signed-urls and https://laravel.com/docs/6.x/filesystem for more info.\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Superbalist](https://github.com/Superbalist) for the original GCS adapter package\n- [Alex Vanderbist](https://github.com/alexvanderbist)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-google-cloud-storage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-google-cloud-storage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-google-cloud-storage/lists"}