如何使用PredefinedAcl函数将ACL设置为publicRead?

huangapple go评论82阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2016年4月12日 20:10:54
  • 转载请务必保留本文链接:https://go.coder-hub.com/36572872.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定