Google Cloud Storage ignoring access control origin headers

后端 未结 1 1289
故里飘歌
故里飘歌 2021-01-18 18:57

I\'m trying to get files via AJAX from google cloud storage on my local host. I have done the following:

Set the CORS for my bucket via gsutil:

gsutil

1条回答
  •  失恋的感觉
    2021-01-18 19:17

    You're using "googleapis.com" instead of "www.googleapis.com". Add the "www" and your code will work.

    It looks like you're not doing any authentication, so you'll also need to make sure that your bucket allows anonymous users to list objects (gsutil acl ch -g allUsers:R gs://bucket-name will set that).

    Next, for anonymous requests, it's a good practice to add an API key parameter associating the request with your Google Cloud project. GCS will allow completely anonymous requests, but they may be blocked if they get too frequent.

    Finally, the CORS policy on a bucket is only respected by the XML API. The JSON API, which is the one with the endpoint of "www.googleapis.com", will happily respond to cross-origin requests without the need to set any special properties on the bucket.

    0 讨论(0)
提交回复
热议问题