Flysystem adapter for Google Cloud Storage

Overview

Flysystem adapter for Google Cloud Storage

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

This package contains a Google Cloud Storage driver for Flysystem.

Notice

This package is a fork from superbalist/flysystem-google-cloud-storage. Changes include:

  • PHP 8 only
  • merged random open PRs from Superbalist's package

Support us

We invest a lot of resources into creating best in class open source packages . You can support us by buying one of our paid products.

We 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. We publish all received postcards on our virtual postcard wall.

Installation

You can install the package via composer:

composer require spatie/flysystem-google-cloud-storage

Authentication

Before you can use the package, you'll need to authenticate with Google. When possible, the credentials will be auto-loaded by the Google Cloud Client.

  1. The client will first look at the GOOGLE_APPLICATION_CREDENTIALS env var. You can use putenv('GOOGLE_APPLICATION_CREDENTIALS=/path/to/service-account.json'); to set the location of your credentials file.
  2. The client will look for the credentials file at the following paths:
    • Windows: %APPDATA%/gcloud/application_default_credentials.json
    • MacOS/Unix: $HOME/.config/gcloud/application_default_credentials.json
  3. If running in Google App Engine, Google Compute Engine or GKE, the built-in service account associated with the app, instance or cluster will be used.

Using this in a Kubernetes cluster? Take a look at Workload Identity.

Usage

Here's an example that shows you have you can call the various functions to manipulate files on Google Cloud.

use Google\Cloud\Storage\StorageClient;
use League\Flysystem\Filesystem;
use Spatie\GoogleCloudStorageAdapter\GoogleCloudStorageAdapter;

$storageClient = new StorageClient([
    'projectId' => 'your-project-id',
    // The credentials can manually be specified by passing in a keyFilePath.
    // 'keyFilePath' => '/path/to/service-account.json',
]);

$bucket = $storageClient->bucket('your-bucket-name');

$adapter = new GoogleCloudStorageAdapter($storageClient, $bucket);

$filesystem = new Filesystem($adapter);

$filesystem->write('path/to/file.txt', 'contents');
$filesystem->update('path/to/file.txt', 'new contents');
$contents = $filesystem->read('path/to/file.txt');
$exists = $filesystem->has('path/to/file.txt');
$filesystem->delete('path/to/file.txt');
$filesystem->rename('filename.txt', 'newname.txt');
$filesystem->copy('filename.txt', 'duplicate.txt');
$filesystem->deleteDir('path/to/directory');

See https://flysystem.thephpleague.com/v1/docs/usage/filesystem-api/ for full list of available functionality

Using a custom storage URI

You can configure this adapter to use a custom storage URI. Read more about configuring a custom domain for Google Cloud Storage here.

When using a custom storage URI, the bucket name will not prepended to the file path:

getUrl('path/to/file.txt'); // "https://storage.googleapis.com/your-bucket-name/path/to/file.txt" // Using custom storage uri: $adapter->setStorageApiUri('http://example.com'); $filesystem = new Filesystem($adapter); $filesystem->getUrl('path/to/file.txt'); // "http://example.com/path/to/file.txt" // You can also prefix the file path if needed: $adapter->setStorageApiUri('http://example.com'); $adapter->setPathPrefix('extra-folder/another-folder/'); $filesystem = new Filesystem($adapter); $filesystem->getUrl('path/to/file.txt'); // "http://example.com/extra-folder/another-folder/path/to/file.txt" ">
use Google\Cloud\Storage\StorageClient;
use League\Flysystem\Filesystem;
use Spatie\GoogleCloudStorageAdapter\GoogleCloudStorageAdapter;

$storageClient = new StorageClient([
    'projectId' => 'your-project-id',
]);
$bucket = $storageClient->bucket('your-bucket-name');
$adapter = new GoogleCloudStorageAdapter($storageClient, $bucket);

// URI defaults to "https://storage.googleapis.com":
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "https://storage.googleapis.com/your-bucket-name/path/to/file.txt"

// Using custom storage uri:
$adapter->setStorageApiUri('http://example.com');
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "http://example.com/path/to/file.txt"

// You can also prefix the file path if needed:
$adapter->setStorageApiUri('http://example.com');
$adapter->setPathPrefix('extra-folder/another-folder/');
$filesystem = new Filesystem($adapter);
$filesystem->getUrl('path/to/file.txt');
// "http://example.com/extra-folder/another-folder/path/to/file.txt"

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.

You might also like...
High-quality cloud service for text translation. 100+ Languages
High-quality cloud service for text translation. 100+ Languages

CloudAPI.Stream High-quality cloud service for text translation. 100+ Languages https://cloudapi.stream/ Class initialization $CAS = new CAS; Key inst

💾 Flysystem adapter for the GitHub storage.

Flysystem Github Requirement PHP = 7.2 CDN List 'github' = "https://raw.githubusercontent.com/:username/:repository/:branch/:fullfilename", 'fastg

Flysystem storage with local metadata storage for speed and manageability.

Laravel Filer This project was started to scratch my itch on our growing Laravel site: Metadata for all files is stored in a local repository - Suppor

Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual

Aliyun oss filesystem storage adapter for laravel 5. You can use Aliyun OSS just like laravel Storage as usual

Laravel Flysystem - a Flysystem bridge for Laravel.
Laravel Flysystem - a Flysystem bridge for Laravel.

Laravel Flysystem Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel. It utilises my Larave

Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel.
Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel.

Laravel Flysystem Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel. It utilises my Larave

Flysystem V2 adapter for the webman

Flysystem V2 adapter for the webman

Microsoft OneDrive adapter for Flysystem 2+

Lexik Flysystem OneDrive Adapter This is a Flysystem 2+ adapter to interact with Microsoft OneDrive API. Setup In your Microsoft Azure portal create a

A Flysystem proxy adapter that enables compression and encryption of files and streams on the fly

Slam / flysystem-compress-and-encrypt-proxy Compress and Encrypt files and streams before saving them to the final Flysystem destination. Installation

Google Cloud Storage filesystem driver for Laravel
Google Cloud Storage filesystem driver for Laravel

Google Cloud Storage filesystem driver for Laravel Google Cloud Storage filesystem driver for Laravel. This started as a fork from Superbalist/laravel

Google Cloud Storage for PHP

Google Cloud Storage for PHP Idiomatic PHP client for Cloud Storage. API documentation NOTE: This repository is part of Google Cloud PHP. Any support

Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS.
Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS.

Cipi is a Laravel based cloud server control panel that supports Digital Ocean, AWS, Vultr, Google Cloud, Linode, Azure and other VPS. It comes with nginx, Mysql, multi PHP-FPM versions, multi users, Supervisor, Composer, npm, free Let's Encrypt certificates, Git deployment, backups, ffmpeg, fail2ban, Redis, API and with a simple graphical interface useful to manage Laravel, Codeigniter, Symfony, WordPress or other PHP applications. With Cipi you don’t need to be a Sys Admin to deploy and manage websites and PHP applications powered by cloud VPS.

Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP.

Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP. When you use this package, you're protected from vendor lock-in, That mean you can connect to any FTP/SFTP storage. Also it's comes with base URL option to connect Gotipath CDN.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

Cloud storage solution for you
Cloud storage solution for you

Attic-API Cloud storage solution for you! Quick Start Setup MySQL server, open config/config.php and change settings according to your database server

Qiniu Resource (Cloud) Storage SDK for PHP

Qiniu Cloud SDK for PHP 安装 推荐使用 composer 进行安装。可以使用 composer.json 声明依赖,或者运行下面的命令。SDK 包已经放到这里 qiniu/php-sdk 。 $ composer require qiniu/php-sdk 直接下载安装,SD

Laravel Package - Files to S3 Like Cloud Storage

This is a Laravel package that handles and make easy the upload, overwrite, delete, cdn purge of files and directories on AWS S3 like cloud storages. It supports a form uploaded file (UploadedFile) or a base64 file string

Private file storage and share with user build with laravel and vue inspired by google drive
Private file storage and share with user build with laravel and vue inspired by google drive

LaravelDrive is a file storage system that allows store private file and share with users build wiht laravel and vue inspired by google drive. Laravel

Releases(1.1.1)
Owner
Spatie
We create products and courses for the developer community
Spatie
Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel.

Laravel Flysystem Laravel Flysystem was created by, and is maintained by Graham Campbell, and is a Flysystem bridge for Laravel. It utilises my Larave

Graham Campbell 492 Feb 4, 2022
Flysystem V2 adapter for the webman

Flysystem V2 adapter for the webman

null 0 Nov 3, 2021
Microsoft OneDrive adapter for Flysystem 2+

Lexik Flysystem OneDrive Adapter This is a Flysystem 2+ adapter to interact with Microsoft OneDrive API. Setup In your Microsoft Azure portal create a

Choosit 3 Nov 19, 2021
A Flysystem proxy adapter that enables compression and encryption of files and streams on the fly

Slam / flysystem-compress-and-encrypt-proxy Compress and Encrypt files and streams before saving them to the final Flysystem destination. Installation

Filippo Tessarotto 27 Jun 4, 2022
Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP.

Gotipath Storage is a file storage library for PHP. It provides one interface to interact with FTP/SFTP. When you use this package, you're protected from vendor lock-in, That mean you can connect to any FTP/SFTP storage. Also it's comes with base URL option to connect Gotipath CDN.

Gotipath 2 Nov 3, 2021
Private file storage and share with user build with laravel and vue inspired by google drive

LaravelDrive is a file storage system that allows store private file and share with users build wiht laravel and vue inspired by google drive. Laravel

Shahadat Hossain 70 Dec 22, 2022
PHP stream wrapper for Flysystem v2

Flystream enables you to use core PHP filesystem functions to interact with Flysystem filesystems by registering them as custom protocols.

Matthew Turland 12 Dec 14, 2022
A stream wrapper for Flysystem V2.

Flysystem Stream Wrapper This package provides a stream wrapper for Flysystem V2. Flysystem V1 If you're looking for Flysystem 1.x support, check out

Martin Mandl 9 Oct 21, 2022
Basic anonymous and registered upload storage for temporary share file self hosted.

TMPShareX Basic anonymous and registered upload storage for temporary share file self hosted. Server Requirement PHP 7.4.8 [Support PHP 8] Nginx 1.19.

Sandy Hermansyah 1 Feb 3, 2022
🌩支持多家云存储的云盘系统 (A project helps you build your own cloud in minutes)

Cloudreve 支持多家云存储驱动的公有云文件系统. 演示站 • 讨论社区 • 文档 • 下载 • Telegram 群组 • 许可证 ✨ 特性 ☁️ 支持本机、从机、七牛、阿里云 OSS、腾讯云 COS、又拍云、OneDrive (包括世纪互联版) 作为存储端 ?? 上传/下载 支持客户端直传

Cloudreve 17k Jan 7, 2023