← Articles 2300

Fixing the cors error in firebase storage on web

By Vinay Saurabh • Published on

This article describes how you can fix this issue in any project on Google Cloud Storage

Fixing the cors error in firebase storage on web

Understanding the CORS Error

Why browsers block cross-origin requests and how it affects Firebase Storage.



Common Scenarios That Trigger CORS

Typical operations that lead to CORS issues in web apps.



Step 1: Install Google Cloud CLI

You'll need the gcloud CLI to modify Firebase Storage CORS settings.


  1. Download and install from: cloud.google.com/sdk/docs/install
  2. Login: gcloud auth login
  3. Set your project: gcloud config set project [your-project-id]

Step 2: Define Your CORS Policy

Create a JSON file that specifies allowed origins and methods.


[
  {
    "origin": ["*"],
    "method": ["GET", "POST", "PUT"],
    "maxAgeSeconds": 3600,
    "responseHeader": ["Content-Type"]
  }
]

Step 3: Apply the CORS Configuration

Upload your policy to Firebase Storage using the CLI.


gsutil cors set cors.json gs://[your-bucket-name]

To find your bucket name, check Firebase Console → Storage → Files tab.


Verifying the Fix

How to confirm if the CORS error is resolved.



Security Best Practices

Keep your CORS rules tight in production environments.



Final Thoughts

A quick fix that avoids hours of debugging.


Setting proper CORS rules is essential for frontend access to Firebase Storage. Do it once, do it right, and keep your project secure.