Google Cloud Storage API - new ACL?



我正在使用Google cloud Storage SDK用于上传资源,但是我遇到问题,使我在上传中使用 acl => ['READER' => 'allUsers']尝试了文件,例如我尝试使用该文件。配置。

无论如何,我希望能够将我上传的所有资源共享给allUsers用户,因此公开授予对图像的访问。

这是我的代码:

public function upload($sourceFilename, $destFilename) {
        $bucket = $this->storage->bucket(self::IMAGE_BUCKET_NAME);
        //Base options
        $options = [
            'name' => $destFilename,
            'validate' => true,
            'acl' => [
                'READER' => 'allUsers'
            ]
        ];
        //Local file read:
        $fileHandle = @fopen($sourceFilename, 'r');
        if ($fileHandle === false) {
            throw new Exception("Failed to open file for upload.");
        }
        //Resumable uploader:
        $uploader = $bucket->getResumableUploader($fileHandle, $options);

        try {
            $object = $uploader->upload();
        } catch (GoogleException $ex) {
            $resumeUri = $uploader->getResumeUri();
            $object = $uploader->resume($resumeUri);
            //do some error handling ?
        }
    }

尝试将'ACL'部分更改为:

'predefinedAcl' => 'publicRead'

最新更新