All Projects → spatie → flysystem-google-cloud-storage

spatie / flysystem-google-cloud-storage

Licence: MIT license
Flysystem v1 adapter for Google Cloud Storage

Programming Languages

PHP
23972 projects - #3 most used programming language

Projects that are alternatives of or similar to flysystem-google-cloud-storage

swarm-gcp-faas
Setup OpenFaaS on Google Cloud with Terraform, Docker Swarm and Weave
Stars: ✭ 15 (-28.57%)
Mutual labels:  google-cloud
argon
Campaign Manager 360 and Display & Video 360 Reports to BigQuery connector
Stars: ✭ 31 (+47.62%)
Mutual labels:  google-cloud
cloudrun-fastapi
FastAPI on Google Cloud Run
Stars: ✭ 112 (+433.33%)
Mutual labels:  google-cloud
google-drive-direct-remote-upload
Directly upload files from the web to Google Drive without saving them completely on the server before.
Stars: ✭ 62 (+195.24%)
Mutual labels:  google-cloud
flysystem-sync
Filesystem sync using Flysystem project.
Stars: ✭ 26 (+23.81%)
Mutual labels:  flysystem
go-bqloader
bqloader is a simple ETL framework to load data from Cloud Storage into BigQuery.
Stars: ✭ 16 (-23.81%)
Mutual labels:  google-cloud
bigquery-kafka-connect
☁️ nodejs kafka connect connector for Google BigQuery
Stars: ✭ 17 (-19.05%)
Mutual labels:  google-cloud
30Days-of-GCP
Resources for the 30 Days of GCP program
Stars: ✭ 26 (+23.81%)
Mutual labels:  google-cloud
cloud-game-servers-examples
Collection of examples for using Google Cloud Game Servers.
Stars: ✭ 28 (+33.33%)
Mutual labels:  google-cloud
vault-demo
Walkthroughs and scripts for my @hashicorp Vault talks
Stars: ✭ 67 (+219.05%)
Mutual labels:  google-cloud
flysystem-stream-wrapper
Provides the ability to register Flysystem filesystems as stream wrappers.
Stars: ✭ 59 (+180.95%)
Mutual labels:  flysystem
sg-food-ml
This script is used to scrap images from the Internet to classify 5 common noodle "mee" dishes in Singapore. Wanton Mee, Bak Chor Mee, Lor Mee, Prawn Mee and Mee Siam.
Stars: ✭ 18 (-14.29%)
Mutual labels:  google-cloud
Cezanne
🎣 Serverless Image Generation Function
Stars: ✭ 29 (+38.1%)
Mutual labels:  google-cloud
dataflow-contact-center-speech-analysis
Speech Analysis Framework, a collection of components and code from Google Cloud that you can use to transcribe audio files to create analytics.
Stars: ✭ 46 (+119.05%)
Mutual labels:  google-cloud
google-storage-plugin
This plugin provides the “Google Cloud Storage Uploader” post-build step for publishing build artifacts to Google Cloud Storage.
Stars: ✭ 30 (+42.86%)
Mutual labels:  google-cloud
bigquery-to-datastore
Export a whole BigQuery table to Google Datastore with Apache Beam/Google Dataflow
Stars: ✭ 56 (+166.67%)
Mutual labels:  google-cloud
souls
SOULs 🔥 Build Serverless Apps faster like Rails. Powered by Ruby GraphQL, RBS/Steep, Active Record, RSpec, RuboCop, and Google Cloud.
Stars: ✭ 327 (+1457.14%)
Mutual labels:  google-cloud
storage-abstraction
Provides an abstraction layer for interacting with a storage; the storage can be local or in the cloud.
Stars: ✭ 36 (+71.43%)
Mutual labels:  google-cloud
yii2-flysystem-component
The League Flysystem Library for Yii Framework
Stars: ✭ 22 (+4.76%)
Mutual labels:  flysystem
notionproxy
Notion as a web site, inspired by react-notion-x.
Stars: ✭ 24 (+14.29%)
Mutual labels:  google-cloud

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

(If you need Google Cloud Storage support on Flysystem v2 or above (or Laravel 9), this package is not for you)

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:

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].