简体   繁体   English

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

[英]Trying to upload to Google cloud storage using Superbalist/flysystem-google-cloud-storage

UPDATE: Fixed it using the code from this PR, I've asked to assist in getting the PR merged, but for now my issues is sorted with a fork.更新:使用此 PR 中的代码修复了它,我已要求协助合并 PR,但现在我的问题是用叉子排序的。

Trying to upload to Google cloud storage via the following package:尝试通过以下 package 上传到 Google 云存储:

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

My integration works fine with fine grained access control, but I need to use uniform access, and any time i set it to be uniform instead of fine grain, i'm no longer able to upload to the bucket, and get the following error:我的集成适用于细粒度访问控制,但我需要使用统一访问,并且任何时候我将其设置为统一而不是细粒度,我不再能够上传到存储桶,并收到以下错误:

{
  "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"
      }
    ]
  }
}

Any ideas what i might be missing to get this working?有什么想法我可能会丢失以使其正常工作吗?

There are an open PR to fix this issue [ Allow uniform access rules on upload ].有一个开放的 PR 来解决这个问题 [ 允许上传时统一访问规则]。

However, Until the acceptance for this PR I used to make a work-around for this issue instead of updating the package files itself by using the mentioned PR changes & Anonymous class in PHP 7但是,在接受此 PR 之前,我曾经使用 Z2FEC392304A5C23AC17CZ 22847F7B 中提到的 PR 更改和匿名 class 来解决此问题,而不是更新 package 文件本身

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;
        }
    };
}

This looks an like known issue of the package Superbalist/laravel-google-cloud-storage这看起来像 package Superbalist/laravel-google-cloud-storage 的已知问题

The only way to work with this package is using fine grained access control, or by using directly the official google cloud storage PHP library .使用这个 package 的唯一方法是使用细粒度的访问控制,或者直接使用官方的谷歌云存储 PHP 库

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM