6

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.

Trying to upload to Google cloud storage via the following package:

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?

André Figueira
  • 6,048
  • 14
  • 48
  • 62

2 Answers2

4

This looks an like known issue of the 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.

Fatih Aytekin
  • 180
  • 1
  • 8
Jan Hernandez
  • 4,414
  • 2
  • 12
  • 18
4

There are an open PR to fix this issue [ Allow uniform access rules on upload ].

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

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;
        }
    };
}
hassan
  • 7,812
  • 2
  • 25
  • 36