简体   繁体   English

Flysystem谷歌云存储适配器统一存储桶

[英]Flysystem Google Cloud Storage adapter Uniform Bucket

I'm trying to user an uniform bucked with flysystem v3.我正在尝试使用带有 flysystem v3 的制服。

https://flysystem.thephpleague.com/docs/adapter/google-cloud-storage/ 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".当我尝试写东西时,我得到“无法在位置写入文件: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.我想有一些选项我没有正确传递。

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

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

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