How do you make many files public in Google Cloud Storage?
Google Cloud-PlatformGoogle Cloud-StorageCloudGoogle Cloud-Platform Problem Overview
I have 1000 files in Google Cloud Storage to make public, or in general a directory hierarchy.
In the Web UI, I can only seem to make one at a time public.
Is there some way to do this.
Google Cloud-Platform Solutions
Solution 1 - Google Cloud-Platform
Run gsutil -m acl set -R -a public-read gs://bucket
- The
-m
issues multiple requests at the same time. - The
-R
issues requests for every object in your bucket. - The
-a
issues requests for every version of every object.
See gsutil help acl
for more info.
At the API layer gsutil issues the following HTTP request:
PUT /bucket/obj?acl HTTP/1.1
Host: storage.googleapis.com
x-goog-acl: public-read
You can see this by using the -D
flag with gsutil
:
gsutil -D setacl public-read gs://bucket/obj
Solution 2 - Google Cloud-Platform
You can make all objects in a bucket public. Here's the link.
>1. Open the Cloud Storage browser in the Google Cloud Platform Console.
>2. In the list of buckets, click on the name of the bucket that you want to make public.
>3. Select the Permissions tab near the top of the page.
>4. Click the Add members button.
> The Add members dialog box appears.
>5. In the Members field, enter allUsers.
>6. In the Roles drop down, select the Storage sub-menu, and click the Storage Object Viewer option.
>7. Click Add.
>
>Once shared publicly, a link icon appears for each object in the public access >column. You can click on this icon to get the URL for the object.
Solution 3 - Google Cloud-Platform
When you run: gsutil -m acl set -R -a public-read gs://bucket
you define public read for all the objects currently in your bucket, but when you upload new files they wont be public by default.
What I found is that is worth to define a bucket default acl as public-read gsutil defacl set public-read gs://bucket
Solution 4 - Google Cloud-Platform
The easiest way to accomplish this would be by using a console.
Click on "Edit bucket permissions"
Enter allUsers
in Add Members.
Then Select Role
> Storage
> Storage Object Viewer
Attention! This will give read permission to all the people on the internet to all the objects in that selected bucket.
Solution 5 - Google Cloud-Platform
Current (Oct/2017) documentation about Hosting a Static Website found here points to:
gsutil acl ch -r -u AllUsers:R gs://bucket-name
Where the -r
does the recursive trick and -u AllUsers:R
gives the public read access.
Solution 6 - Google Cloud-Platform
To copy and paste on Erik's behalf, this worked consistently for me:
> Making groups of objects publicly readable > > To make all objects in a bucket publicly readable: > > CONSOLEGSUTILREST APIS Use the gsutil iam ch command, replacing > [VALUES_IN_BRACKETS] with the appropriate values: >
gsutil iam ch allUsers:objectViewer gs://[BUCKET_NAME]
Solution 7 - Google Cloud-Platform
You can make all objects in a public range, this link has more information: https://cloud.google.com/storage/docs/access-control/making-data-public
If you can't, in your console, log into your bucket and click "Edit bucket permissions" - Enter allUsers in Add Members. Then Select Role > Storage > Storage Object Viewer
Solution 8 - Google Cloud-Platform
Apr, 2022 Update:
You can allow all users to read files in your bucket.
For example, in Bucket details, click "PERMISSIONS" then "ADD":
Then, type "allUsers":
Then, choose the role "Storage Legacy Object Reader" so that all users can read files:
Then, click "SAVE":
Then, you will be asked as shown below so click "ALLOW PUBLIC ACCESS":
Finally, you can allow all users to read files in your bucket: