【发布时间】:2019-08-21 17:44:59
【问题描述】:
我正在尝试使用 Laravel (PHP) 将图像上传到我的 Firebase 存储。
public function uploadObject($bucketName, $objectName, $source) {
$projectId = 'cloudestate-d10da';
$storage = new StorageClient([
'projectId' => $projectId,
'keyFilePath' => __DIR__.'/StorageAcc.json'
]);
$file = fopen($source, 'r');
$bucket = $storage->bucket("images");
$object = $bucket->upload($file, [
'name' => $objectName
]);
printf('Uploaded %s to gs://%s/%s' . PHP_EOL, basename($source), $bucketName, $objectName);
}
但是当我尝试运行它时,我收到以下错误:
{
"error": {
"errors": [
{
"domain": "global",
"reason": "forbidden",
"message": "storageacc@cloudestate-d10da.iam.gserviceaccount.com does not have storage.objects.create access to images/testezc.png."
}
],
"code": 403,
"message": "storageacc@cloudestate-d10da.iam.gserviceaccount.com does not have storage.objects.create access to images/testezc.png."
}
}
我还赋予了我的服务帐户“所有者”角色,但似乎没有修复错误。
【问题讨论】:
-
是否启用了存储 API? console.cloud.google.com/apis/library/…
-
是的,已启用。
-
我们也面临同样的问题。只有默认存储桶有效。自定义存储桶不起作用。
-
您找到解决方案了吗?我也有同样的问题。我启用了谷歌云存储定价。我启用了 api:
Cloud Storage for Firebase API和Storage API。我总是得到does not have storage.objects.create access to test-lab...我的角色几乎拥有所有管理员权限。我真的对错误消息感到困惑。 -
你有大火或火花计划吗?
标签: php firebase google-cloud-storage firebase-storage