GSUTIL cp file from server to bucket and make file public
Asked Answered
P

1

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?

Pride answered 11/4, 2018 at 10:12 Comment(0)
I
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.

Imputation answered 11/4, 2018 at 11:36 Comment(1)
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 cloud.google.com/storage/docs/access-control/iam-roles.Procumbent

© 2022 - 2024 — McMap. All rights reserved.