6

Using this command in my server from a php file:

exec(gsutil cp /path/to/file/on/server/namefile.ext gs://nameBucket/dir/namefile.ext > /dev/null 2>&1) 

i got the namefile.ext on bucket, in the correct directory...but need to make this file public readable.

Already tried to put this command (at the end of file, for make that public) but nothing to do:

exec(gsutil iam ch allUsers:objectViewer gs://nameBucket/dir/namefile.ext > /dev/null 2>&1)

So, upload works but I need to make file readable without my interaction from "browser" of bucket. There is a way to do this? Maybe into cp command?

tidpe
  • 325
  • 3
  • 15

1 Answers1

5

The gsutil iam ch allUsers:objectViewer command you used is meant to make all objects in a bucket publicly readable, but you provided it with the url of the object.

So, if you want to make the specific file publicly readable:

gsutil acl ch -u AllUsers:R gs://nameBucket/dir/namefile.ext

If you want to make all objects in a bucket publicly readable:

gsutil iam ch allUsers:objectViewer gs://nameBucket/

This is documented here.

LundinCast
  • 9,412
  • 4
  • 36
  • 48
  • For the `acl ch` command above, the IAM alternative is `gsutil iam ch allUsers:legacyObjectReader gs://bucket/obj`. You can check out what roles are available at https://cloud.google.com/storage/docs/access-control/iam-roles. – mhouglum Apr 11 '18 at 22:19