Karthic Rao
Karthic Rao

Reputation: 3754

Making Newly created file public on Google Cloud Storage Go runtime Client API

Im using Google Cloud Storage Go Runtime client API to write a string from GO server into a file in the default bucket . Here is the code

wc := storage.NewWriter(d.ctx, bucket, fileName)
wc.ContentType = "text/plain"
if _, err := wc.Write([]byte(myData)); err != nil {
        d.errorf("createFile: unable to write data to bucket %q, file %q: %v", bucket, fileName, err)
        return
}

But im Not able set right ACL permissions on the wc object to make the file public ?? How to do achieve it so that the created file becomes public ?

Upvotes: 2

Views: 1264

Answers (2)

OhhhThatVarun
OhhhThatVarun

Reputation: 4321

You can do the same by this also.

acl := client.Bucket(bucket).Object(object).ACL()
if err := acl.Set(ctx, storage.AllUsers, storage.RoleReader); err != nil {
        return err
}

Here is the link to the docs.

Upvotes: 1

Brandon Yarbrough
Brandon Yarbrough

Reputation: 38369

Try setting:

wc.ACL = []storage.ACLRule{{storage.AllUsers, storage.RoleReader}}

Alternately, you can also change the default object ACL on the bucket so that newly created objects default to being publicly readable.

Upvotes: 4

Related Questions