英文:
How to set the ACL to publicRead with PredefinedAcl function?
问题
如果要将ACL设置为publicRead,可以使用API中的func (*ObjectsInsertCall) PredefinedAcl
函数。以下是修改后的代码示例:
if res, err := service.Objects.Insert(*bucketName, object).Media(file).PredefinedAcl("publicRead").Do(); err == nil {
fmt.Printf("Created object %v at location %v\n\n", res.Name, res.SelfLink)
} else {
fatalf(service, "Objects.Insert failed: %v", err)
}
在原有的代码中,通过在.PredefinedAcl("publicRead")
中传入"publicRead"
参数来设置ACL为publicRead。这样修改后,上传的对象将具有公共读取权限。
英文:
if res, err := service.Objects.Insert(*bucketName, object).Media(file).Do(); err == nil {
fmt.Printf("Created object %v at location %v\n\n", res.Name, res.SelfLink)
} else {
fatalf(service, "Objects.Insert failed: %v", err)
}
I want to modify this code to set the ACL to publicRead, I have noticed there is a function in the API func (*ObjectsInsertCall) PredefinedAcl
but I can't find how to use it.
答案1
得分: 0
根据我在文档中找到的内容,看起来这样做应该可以...
if res, err := service.Objects.Insert(*bucketName, object).Media(file).PredefinedAcl("publicRead").Do(); err == nil {
fmt.Printf("在位置 %v 创建了对象 %v\n\n", res.SelfLink, res.Name)
} else {
fatalf(service, "Objects.Insert 失败:%v", err)
}
(将其插入到 Do()
调用之前。)希望对你有帮助,但结果可能因人而异。
英文:
Going by what i found in the docs, it looks like this would do it...
if res, err := service.Objects.Insert(*bucketName, object).Media(file).PredefinedAcl("publicRead").Do(); err == nil {
fmt.Printf("Created object %v at location %v\n\n", res.Name, res.SelfLink)
} else {
fatalf(service, "Objects.Insert failed: %v", err)
}
(Inserted it right before the Do()
call.) HTH, YMMV, etc.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论