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.
When App Engine receives a request for a URL beginning with /static , it maps the remainder of the path to files in the ./public directory. If an appropriate file is found in the directory, the contents of that file are returned to the client. The /. * handler matches all other URLs and directs them to your app.
Cloud Storage can host static assets for dynamic web apps. The benefits of using Cloud Storage instead of serving directly from your app include: Cloud Storage essentially works as a content delivery network.
What are the advantages of hosting static websites on Google Cloud Storage? 1. You get automatic scaling with no additional effort. (Cloud Storage scales automatically to serve a large volume of traffic.)
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.
Or you can upload that file using the gsutil with public read right away:
gsutil cp -a public-read custom.css gs://my_backet
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With