LoginSignup
9
8

More than 5 years have passed since last update.

Google Cloud Storageで適当にファイルを公開する方法

Last updated at Posted at 2016-10-06

Web Siteにのせるアイコンの画像なんかを適当にGoogle Cloud Storage (以下GCS)で公開する方法について

料金は無料ではないので、無料が良い場合は別の方法をおすすめします。

Step 0 Google Cloud Platform Projectの作成

無料トライアル 辺りから適当にGCP Projectを作りましょう。

Step 1 Bucketを作る

  • GCP ProjectのメニューからStorageを選択
  • バケットの作成を選択

Bucket名

  • ファイル公開時のURLに含まれるので、公開されて良い名前かつDNSの命名規則に従う必要がある。
  • GCS全体でUniqueである必要がある。

Bucket Class

  • Standard を選択する

Locale

  • Asia を選択する

Step 2 Bucketの中にファイルをUploadする

ブラウザ上でUploadする or gsutilを利用してUploadする

gsutil example

gsutil cp arcanine.png gs://hoge/sinmetal.png

Step 3 ObjectのACLを変更する

一般公開をぽちっと押すと公開状態になる

gsutil example

gsutil acl ch -u AllUsers:R gs://hoge/sinmetal.png

Step 4 Cache Control Headerの調整

デフォルトでEdge Cacheにキャッシュされるようになっているので、そのExpireを調整する

Option

ファイルUpload, キャッシュヘッダーの設定, ACLの設定まで、一発でやるコマンドは以下

gsutil -h "Cache-Control: public,max-age=60" cp -a public-read arcanine.png gs://hoge/sinmetal.png
9
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
8