Even with this configuration, when you run gsutil cors get gs://your-bucket
you will need to initiate the initial POST request according to @Craig's answer:
[{"maxAgeSeconds": 3600, "method": ["GET", "PUT", "POST", "HEAD", "DELETE"], "origin": ["*"], "responseHeader": ["*"]}]
.
Using, for example, golang, it's easy to pass Origin
to a gcloud request. With r http.Request
, you can execute r.Header.Get("Origin")
and pass it to the function that calls POST on gcloud. This is the function I wrote in golang:
func GetUploadURL(bucket, object, contentType, origin string, expires time.Time) (string, error) { url, err := storage.SignedURL(bucket, object, &storage.SignedURLOptions{ GoogleAccessID: " your-service-account@your-gcloud-project.iam.gserviceaccount.com ", PrivateKey: pkey, // set this in package init() function Method: http.MethodPost, Expires: expires, ContentType: contentType, Headers: []string{"x-goog-resumable:start"}, }) if err != nil { return "", err } req, err := http.NewRequest("POST", url, nil) if err != nil { return "", err } req.Header.Set("Content-Type", contentType) req.Header.Set("x-goog-resumable", "start") req.Header.Set("Origin", origin) resp, err := http.DefaultClient.Do(req) if err != nil { return "", err } defer resp.Body.Close() return resp.Header.Get("Location"), nil }