1

我需要从移动 APP 上传图像,所以我们有 API 可以获取 base64 字符串图像并将其上传到服务器。它在我们当前的服务器上运行良好,但现在我们正在迁移到 Google Cloud,所以它无法运行

当我从浏览器访问图像时,它显示错误响应我需要 PHP 代码中的解决方案

我已经为此放置了代码

/* working fine in current server */            
$file = $DIR.$imagename;
$ifp = fopen($file, "wb"); 
$data = explode(',', $base64img);
fwrite($ifp, base64_decode($data[1])); 
fclose($ifp);


/* Now i have changed above current server code for Gcloud as following */
$storage = new StorageClient([
    'projectId' => getenv("PROJECT_ID"),
]);
$bucket = $storage->bucket(getenv("GOOGLE_STORAGE_BUCKET"));

$object = $bucket->upload(file_get_contents(base64_decode($data[1])), [
    'name' => $file,
    'predefinedAcl' => 'publicRead',
]);

现在,当我从浏览器访问图像 URL 时,它显示以下响应并且文件未在 gcloud 上上传,所有权限都已获得

网址:https ://storage.googleapis.com/mydomain.appspot.com/uploads/users/111111/docs/12241/92ddc8390754da02b4e8d34d6a33680.jpg

显示以下错误:

<Error>
    <Code>AccessDenied</Code>
    <Message>Access denied.</Message>
    <Details>Anonymous caller does not have storage.objects.get access to mydomain.appspot.com/uploads/users/111111/docs/12241/92ddc8390754da02b4e8d34d6a33680d.jpg.</Details>
</Error>
4

0 回答 0