Is it possible to serve static files on Google Clo

2019-02-22 04:55发布

First, Build a site www.example.com with Google App Engine https://cloud.google.com/products/

Second, Upload a static image example.jpg to Google Cloud Storage https://cloud.google.com/products/cloud-storage aka https://developers.google.com/storage/

Is it possibe to serve the example.jpg as http://www.example.com/images/example.jpg? instead of using a subdomain such as images.example.com or cdn.example.com etc

The reason I want to do this is because I want to make it easier to move my site to a VPS when necessary.

2条回答
Summer. ? 凉城
2楼-- · 2019-02-22 05:14

You have setup Google Cloud Storage (GCS) https://cloud.google.com/products/cloud-storage aka https://developers.google.com/storage/

You could not serve your image example.jpg that uploaded to Google Cloud Storage (GCS) as http://www.example.com/images/example.jpg when you have assigned your www.example.com pointed other than GCS (c.storage.googleapis.com).

If you insist to serve with the domain, you may consider to parsing the images in base64code when you could redirecthttp://www.example.com/images/example.jpg via .htaccess to a dynamic file where you can put the code to print out the image on the fly like so:

header("Location: http://mybucket/resample/example.jpg");

You may also consider to put your static files like js, html, css, etc in the bucket and access those files to act like a dynamic content via Google App Engine (GAE).

查看更多
霸刀☆藐视天下
3楼-- · 2019-02-22 05:23

I don't believe so, no. A single domain name must route to either Google Cloud Storage or Google App Engine.

You could cheat, mind you. You could configure your app engine app to take all requests for, say "/images/X" and redirect them to images.example.com/X, or you could have your app read the data from GCS and feed it back to the user directly from app engine, but neither of those are a good solution.

If you wanted to move to a VPS later, you could perhaps configure the VPS to handle two domains, one for images and one for dynamic content.

查看更多
登录 后发表回答