我需要第三方才能将一些文件上传到Google Cloud Storage存储桶。授予他们访问权限的最佳(或最简单)方法是什么?
答案 0 :(得分:4)
前两种方法要求用户具有有效的Google Account
。我在这个答案中忽略了Google Identity Platform
。如果用户有一个Gmail Account
,则意味着他们也有一个Google Account
。第三种方法使用Google服务帐户。
方法1:使用Google Cloud Storage控制台:
转到Storage
-> Browser
。
检查所需的存储桶。在permissions
下的右侧面板中,单击Add
按钮。
添加用户的Google帐户电子邮件地址。选择Storage Object Creator
。
授予的角色是roles/storage.objectCreator
。该角色授予用户创建存储桶中对象的权限,但用户无法删除或覆盖对象。
方法2:使用gsutl CLI:
gsutil iam ch user:username@example.com:ObjectCreator gs://examplebucket
读取当前存储区IAM策略的命令:
gsutil iam get gs://examplebucket
方法3:使用Google服务帐户
在Google Cloud Console中创建一个Google服务帐户
IAM & admin
-> Service accounts
CREATE SERVICE ACCOUNT
Service account name
和Service account description
CREATE
Service account permissions
中,选择一个角色。Storage
-> Storage Object Creator
CONTINUE
Create key
JSON
单选按钮Key type
您现在拥有Google Service Account
个凭据,可以使用gsutil
,gcloud
和软件程序进行设置。
答案 1 :(得分:0)
您授予第三方客户访问权限以将文件上传到Google Cloud Storage存储桶的方式与另一种编程语言不同。在PHP中,您将编写如下内容:
$ options = ['gs_bucket_name'=> $ my_bucket]; $ upload_url = CloudStorageTools :: createUploadUrl('/ upload / handler',$ options);
并获得一个上传URL。您可以在线document在线“允许用户上传文件”中找到有关此解决方案的更多详细信息。