php - 尝试使用 Superbalist/flysystem-google-cloud-storage 上传到 Google 云存储

标签 php google-cloud-storage storage flysystem

更新:使用此 PR 中的代码修复了它,我已要求协助合并 PR,但现在我的问题是用 fork 排序的。

尝试通过以下包上传到谷歌云存储:

https://github.com/Superbalist/flysystem-google-cloud-storage#usage

我的集成在细粒度访问控制下运行良好,但我需要使用统一访问,并且任何时候我将其设置为统一而不是细粒度,我无法再上传到存储桶,并收到以下错误:

{
  "error": {
    "code": 400,
    "message": "Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access.",
    "errors": [
      {
        "message": "Cannot insert legacy ACL for an object when uniform bucket-level access is enabled. Read more at https://cloud.google.com/storage/docs/uniform-bucket-level-access.",
        "domain": "global",
        "reason": "invalid"
      }
    ]
  }
}

任何想法我可能会缺少让这个工作?

最佳答案

有一个公开的 PR 来解决这个问题 [ Allow uniform access rules on upload ]。
但是,在接受此 PR 之前,我曾经解决此问题,而不是通过使用 PHP 7 中提到的 PR 更改和匿名类来更新包文件本身

public function resolveAdapter ($storageClient, $bucket)
{
    return new class ($storageClient, $bucket) extends GoogleStorageAdapter {
        protected function getOptionsFromConfig(\League\Flysystem\Config $config)
        {
            $options = [];

            if (empty($this->bucket->info()['iamConfiguration']['uniformBucketLevelAccess']['enabled'])) {
                if ($visibility = $config->get('visibility')) {
                    $options['predefinedAcl'] = $this->getPredefinedAclForVisibility($visibility);
                } else {
                    $options['predefinedAcl'] = $this->getPredefinedAclForVisibility(AdapterInterface::VISIBILITY_PRIVATE);
                }
            }

            if ($metadata = $config->get('metadata')) {
                $options['metadata'] = $metadata;
            }

            return $options;
        }
    };
}

关于php - 尝试使用 Superbalist/flysystem-google-cloud-storage 上传到 Google 云存储,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61779218/

相关文章:

python - 大查询存储。 Python。并行读取多个流(多处理)

node.js - 从 Firebase/Google Cloud Storage 读取作为 Node.js 函数中的缓冲区

php - 使 <div> 出现在当前滚动位置

php - 从 Laravel 框架创建一个在线用户(问题)

php - 使用 phpseclib 从远程服务器下载文件

php - 将动态数量的复选框插入多对多关系数据库

c# - 谷歌云存储 InsertMediaUpload 服务 BaseUri ArgumentNullException

linux - 在 Oracle 12c 中移动数据文件后操作系统存储不释放

python - 在 Python 和 MySQL 中存储科学记数法的最有效方式

javascript - 清除网站的存储持久性标志