1

I'm trying to user an uniform bucked with flysystem v3.

https://flysystem.thephpleague.com/docs/adapter/google-cloud-storage/

    $clientOptions = [
        'projectId' => "project-id",
        "keyFile"   => "file.json",
    ];


    $storageClient = new \Google\Cloud\Storage\StorageClient($clientOptions);
    $bucket = $storageClient->bucket("bucket_name");
    $fs = new \League\Flysystem\Filesystem(new \League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter($bucket, ''));

    $fs->write("xx.txt" , "xx");

When i try to write something i get "Unable to write file at location: xx.txt". If i switch to fine-grained everithing works fine.

Any ideea what i'm doing wrong? I guess there are some options i'm not passing right.

Emanuel
  • 359
  • 4
  • 21
  • Interesting, I'm getting the same error today, one day after this question has been asked :) Any chance you were able to find out what was wrong? – Mike May 13 '22 at 16:32
  • Didnt get any solution, i tried to adapt the solution from v1, but as far i didnt have any luck because of the new source code structure of v3. https://stackoverflow.com/questions/61779218/trying-to-upload-to-google-cloud-storage-using-superbalist-flysystem-google-clou – Emanuel May 13 '22 at 20:09

1 Answers1

1

This is the solution i got to after loosing some hair :)

    $storageClient = new \Google\Cloud\Storage\StorageClient($clientOptions);
    $this->bucket = $storageClient->bucket($this->settings["set_bucket"]);

    //uniform bucket
    if (!empty($this->bucket->info()['iamConfiguration']['uniformBucketLevelAccess']['enabled'])) {
        $config = [ 
            'visibility'            => "noPredefinedVisibility",
            'directory_visibility'  => "noPredefinedVisibility",
        ];
    } else {
        $config = "";
    }

    $this->fs = new \League\Flysystem\Filesystem(
            new \League\Flysystem\GoogleCloudStorage\GoogleCloudStorageAdapter(
                $this->bucket, 
                ''
            ),
            $config
        );
Emanuel
  • 359
  • 4
  • 21