halalsoft / laravel-google-cloud-storage
为 Laravel 定制的 Google Cloud Storage flysystem
v0.2.2
2020-10-06 13:37 UTC
Requires
- php: >=7.0.0
- illuminate/filesystem: >=5.6
- illuminate/support: *
- league/flysystem-aws-s3-v3: ^1.0
- league/flysystem-cached-adapter: ^1.0
This package is auto-updated.
Last update: 2024-09-15 02:52:28 UTC
README
为 Laravel 提供的 Google Cloud Storage 文件系统。
这是使用 flysystem-aws-s3-v3。因为 Google Cloud Storage 使用与 Amazon S3 相同的 API,所以实际上我只是使用了相同的驱动,并将其重命名为 gcs。
安装
composer require halalsoft/laravel-google-cloud-storage
将新磁盘添加到您的 filesystems.php
配置文件中
'gcs' => [ 'driver' => 'gcs', 'key' => env('GCP_ACCESS_KEY_ID'), 'secret' => env('GCP_SECRET_ACCESS_KEY'), 'bucket' => env('GCP_BUCKET'), ],
以上是所需配置,以下是其他可能的配置
'gcs' => [ 'driver' => 'gcs', 'key' => env('GCP_ACCESS_KEY_ID'), 'secret' => env('GCP_SECRET_ACCESS_KEY'), 'bucket' => env('GCP_BUCKET'), 'visibility' => 'public', //Default visibility, you can set public or private 'url' => "https://custom.domain.com", //Your public URL (if you use custom domain or CDN) 'endpoint' => "https://storage.googleapis.com", //Your endpoint URL (if you use custom driver) 'cache' => [ 'store' => 'memcached', 'expire' => 600, 'prefix' => 'cache-prefix', ], ],
使用方法
您可以使用大多数 Laravel 文件系统 API
示例
$disk = Storage::disk('gcs'); // create a file $disk->put('avatars/1', $request->file("image")); // check if a file exists $exists = $disk->exists('image.jpg'); // get file last modification date $time = $disk->lastModified('image1.jpg'); // copy a file $disk->copy('old/image1.jpg', 'new/image1.jpg'); // move a file $disk->move('old/image1.jpg', 'new/image1.jpg'); // get url to file $url = $disk->url('avatar/yaskur.jpg');