Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

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?

like image 298
André Figueira Avatar asked May 13 '20 15:05

André Figueira


2 Answers

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.

like image 52
Jan Hernandez Avatar answered Nov 04 '22 21:11

Jan Hernandez


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;
        }
    };
}
like image 30
hassan Avatar answered Nov 04 '22 20:11

hassan