0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

【GCS】Google Cloud StorageのBucketにCORSを設定【最速】

Last updated at Posted at 2022-04-09

バケットにCORSを設定

echo '[
  {
    "origin": ["*"],
    "responseHeader": ["Accept", "Accept-Language", "Content-Language", "Content-Type"],
    "method": ["GET","HEAD","POST","PUT","DELETE","CONNECT","OPTIONS","TRACE","PATCH"],
    "maxAgeSeconds": 3600
  }
]' | gsutil cors set /dev/stdin gs://$DEVSHELL_PROJECT_ID.appspot.com

反映に1分ほどかかります

CORSを確認
gsutil cors get gs://$DEVSHELL_PROJECT_ID.appspot.com

バケット/オブジェクトの一般公開

gsutil iam ch allUsers:objectViewer gs://$DEVSHELL_PROJECT_ID.appspot.com
公開アクセス権を削除
gsutil iam ch -d allUsers:objectViewer gs://$DEVSHELL_PROJECT_ID.appspot.com
Create a bucket
gcloud app create --region asia-northeast2
書き込み権限の付与
gsutil iam ch allUsers:objectCreator gs://$DEVSHELL_PROJECT_ID.appspot.com
書き込み権限の削除
gsutil iam ch -d allUsers:objectCreator gs://$DEVSHELL_PROJECT_ID.appspot.com

参考

Access-Control-Allow-Origin

Access to fetch at 'https://storage.googleapis.com/google.appspot.com/index.html' from origin 'https://cloud.google.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://storage.googleapis.com/google.appspot.com/index.html. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 403.

Uncaught (in promise) TypeError: NetworkError when attempting to fetch resource.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://storage.cloud.google.com/google.appspot.com/index.html. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 302.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://storage.cloud.google.com/google.appspot.com/index.html. (Reason: CORS request did not succeed). Status code: (null).

GET https://storage.cloud.google.com/google.appspot.com/index.html net::ERR_FAILED 302

The specified bucket does not exist.

Access denied. Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.

<Error>
  <Code>AccessDenied</Code>
  <Message>Access denied.</Message>
  <Details>Anonymous caller does not have storage.objects.get access to the Google Cloud Storage object.</Details>
</Error>

0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?