techdyn / google-storage-meta-bucket
一个简单的 GCP 存储桶包装器,用于自动在上传的文件上设置元数据(缓存控制等)。
v1.1
2020-06-25 02:15 UTC
Requires
- php: ^7.2
- google/cloud-storage: ^1.0
This package is auto-updated.
Last update: 2024-09-25 12:27:43 UTC
README
一个简单的 GCP 存储桶包装器,用于自动在上传的文件上设置元数据。
元数据参考: https://cloud.google.com/storage/docs/metadata
为可能不允许您配置存储桶对象元数据(例如 Cache-Control)的其他库而创建。
兼容
- https://github.com/1up-lab/OneupFlysystemBundle
- https://github.com/dustin10/VichUploaderBundle(使用 Flysystem)
- https://github.com/liip/LiipImagineBundle(使用 Flysystem)
安装
需求: https://github.com/googleapis/google-cloud-php-storage
首先,安装 PHP 的首选依赖管理器,Composer。
安装包装器
$ composer require techdyn/google-storage-meta-bucket
示例
require 'vendor/autoload.php'; use TechDyn\GoogleStorageMetaBucket\Storage\ProxyStorageClient; $storage = new ProxyStorageClient(); // ProxyStorageClient extends Google\Cloud\Storage\StorageClient; $bucket = $storage->bucket('my_bucket'); // MetaBucket extends Google\Cloud\Storage\Bucket // https://cloud.google.com/storage/docs/metadata $bucket->setOption('cacheControl', 'no-cache, max-age=60'); // $name uses metadata field written as camelCase // Upload a file to the bucket. $bucket->upload( fopen('/data/file.txt', 'r') );
Symfony & Flysystem
# services.yaml parameters: gcp_client_options: projectId: 'gcp-project-id' keyFilePath: '%kernel.project_dir%/config/gcp/service.json' # Optional - if not configured externally gcp_storage_bucket: 'name-of-bucket' services: google_cloud_storage.client: class: TechDyn\GoogleStorageMetaBucket\Storage\ProxyStorageClient arguments: ['%gcp_client_options%'] google_cloud_storage.bucket: class: TechDyn\GoogleStorageMetaBucket\Storage\MetaBucket factory: ['@google_cloud_storage.client', bucket] arguments: ['%gcp_storage_bucket%'] calls: - method: setOption arguments: - 'cacheControl' - 'no-cache, max-age=60'
Flysystem
使用:https://github.com/1up-lab/OneupFlysystemBundle
# packages/oneup_flysystem.yaml # Read the documentation: https://github.com/1up-lab/OneupFlysystemBundle/tree/master/Resources/doc/index.md oneup_flysystem: adapters: gcp_storage_adapter: googlecloudstorage: client: google_cloud_storage.client bucket: google_cloud_storage.bucket prefix: ~ filesystems: gcp_storage_fs: adapter: gcp_storage_adapter mount: gcp_storage_fs
Vich Uploader
使用:https://github.com/dustin10/VichUploaderBundle
# packages/vich_uploader.yaml vich_uploader: db_driver: orm storage: flysystem mappings: uploaded_images: uri_prefix: 'https://%gcp_storage_bucket%.storage.googleapis.com' # https://name-of-bucket.storage.googleapis.com or your custom domain upload_destination: gcp_storage_fs namer: vich_uploader.namer_uniqid inject_on_load: false delete_on_update: true delete_on_remove: true
Liip Imagine
使用:https://github.com/liip/LiipImagineBundle
# packages/liip_imagine.yaml # See dos how to configure the bundle: https://symfony.com.cn/doc/current/bundles/LiipImagineBundle/basic-usage.html liip_imagine: driver: "gd" # valid drivers options include "gd" or "gmagick" or "imagick" loaders: gcp_loader: flysystem: filesystem_service: oneup_flysystem.gcp_storage_fs_filesystem data_loader: gcp_loader resolvers: gcp_cache: flysystem: root_url: 'https://%gcp_storage_bucket%.storage.googleapis.com' filesystem_service: oneup_flysystem.gcp_storage_fs_filesystem filter_sets: thumb_default: data_loader: gcp_loader cache: gcp_cache quality: 75 filters: downscale: { max: [64, 64], mode: outbound }