google-cloud-platformcorsgoogle-cloud-storagegoogle-cloud-shellretool

(Retool) query: Failed to upload. This might be due to a CORS issue on the bucket, so please double check that your CORS settings are correct


I failed to upload a file to Cloud Storage on GCP from Retool many times and always got the error below:

enter image description here

query: Failed to upload. This might be due to a CORS issue on the bucket, so please double check that your CORS settings are correct.

Actually, I made cors.json with the command below on Cloud Shell:

vi cors.json

Then, wrote the code below to cors.json:

[
  {
    "origin": ["https://myorigin.retool.com"],
    "method": ["*"],
    "responseHeader": ["Content-Type"],
    "maxAgeSeconds": 3600
  }
]

Finally, set cors.json for my bucket in Cloud Storage, GCP running the command below:

gsutil cors set cors.json gs://mybucket-bc123.appspot.com

In addition, the access control of the bucket is "Fine-grained".

enter image description here

Are there any solutions to upload a file to Cloud Storage on GCP from Retool?


Solution

  • Add "x-goog-acl" to "responseHeader" for the access control of the bucket "Fine-grained":

    [
      {
        "origin": ["https://myorigin.retool.com"],
        "method": ["*"],                
        "responseHeader": ["Content-Type", "x-goog-acl"],
        "maxAgeSeconds": 3600           // ↑↑↑ Here ↑↑↑
      }
    ]
    

    In addition, if the access control of the bucket is "Uniform":

    enter image description here

    "x-goog-acl" is not needed:

    [
      {
        "origin": ["https://myorigin.retool.com"],
        "method": ["*"],
        "responseHeader": ["Content-Type"],
        "maxAgeSeconds": 3600
      }
    ]