Trying to upload to Google cloud storage using Superbalist/flysystem-google-cloud-storage
Asked Answered
H

2

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?

Horwath answered 13/5, 2020 at 15:56 Comment(0)
G
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.

Galactose answered 20/5, 2020 at 20:18 Comment(2)
It's cool, I managed to get it working, by making a fix to the Superbalist package.Endopeptidase
@AndréFigueira to help people with the same issue and avoid duplicated questions, could you post your code patch?Galactose
C
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;
        }
    };
}
Cantharides answered 2/9, 2020 at 13:16 Comment(1)
You are a life savior :)Lark

© 2022 - 2024 — McMap. All rights reserved.