Hacktisch
Hacktisch

Reputation: 1514

Set all files in Google Cloud Storage Bucket to public by default

I am trying to set the files that are uploaded to a bucket to public by default.

When editing the bucket permissions, I get the popup below which I don't understand and I can't find any documentation about it. How do I set availability to the public?

The 'entity' selectboxes have the options: domain, group, user, project

The settings currently don't seem to set the files to public, because when I try to access a file through the url obtained with CloudStorageTools::getPublicUrl($fileName, false) I get:

<Error>
<Code>NoSuchKey</Code>
<Message>The specified key does not exist.</Message>
</Error>

enter image description here

Upvotes: 1

Views: 2455

Answers (2)

Braian Coronel
Braian Coronel

Reputation: 22867

Making Data Public

Active Google Cloud Shell

gsutil acl ch -u AllUsers:R gs://[BUCKET_NAME]/[OBJECT_NAME]

If successful, the response looks like the following example:

Updated ACL on gs://[BUCKET_NAME]/[OBJECT_NAME]

In the command, in the path after choosing the bucket, the CamelCase writing style must be respected.


I recommend applying the command to each file separately to get the short URL. Because if we assign the permission to the directory it will be possible to access the files but through a long URL.

Short URL:

https://storage.googleapis.com/[BUCKET_NAME]/[FILE_PATH]/[FILE]

Upvotes: -1

Matthias Winkelmann
Matthias Winkelmann

Reputation: 16384

You;ll want to set an ACL for that:

gsutil defacl set public-read gs://bucket

Upvotes: 5

Related Questions