7
votes

I wanted to serve static files stored in google cloud storage for app hosted in app engine. In HTML file, I used

<link href="https://storage.cloud.google.com/my_bucket/custom.css" rel="stylesheet">

It works properly, if the google account of logged in user has permission to access bucket. Since app can be accessed by anyone who will not have access to my bucket and in such case, static files will not be served.

Is it possible to make static files in bucket publicly available? I made static file(custom.css) as 'shared publicly'(ACL set to 'public-read') but still other users can't access it.

2
Did you do this by setting Default ACL on the bucket after you added the file?Peter Knego
Ya. I used files.gs.create("/gs/my_bucket/custom.css", acl='public-read').rajpy

2 Answers

7
votes

I'm not sure how you are uploading your files and why the public read is not set correctly, but you could also change that through the Google Cloud Storage Manager. Simply locate the bucket and the file and click on the Share Publicly checkmark and you'll get the link.

list of files in the bucket on cloud storage

Or you can upload that file using the gsutil with public read right away:

gsutil cp -a public-read custom.css gs://my_backet
1
votes

Beside of manually change each of the static files through Google Cloud Storage Manager you can also set your bucket to be publically viewable using gsutil:

Use acl to set public-read on current bucket objects

gsutil -m acl set -R -a public-read gs://BUCKET_NAME

Use defacl to set as default for future uploads:

gsutil -m defacl set public-read gs://BUCKET_NAME

The "shared publicly" check box will be then automatically checked for every files uploaded.

For accessing bucket, make sure that you have enter an authorized id or email for the groups and users and a domain for the bucket permission otherwise you will get error message like:

'DefAclCommand' object has no attribute 'continue_on_error'

You can do also in Console or Using IAM roles.