Step-by-Step Instructions to Enable CORS Using gsutil
¶
Step 1: Install Google Cloud SDK¶
- Download and Install the Google Cloud SDK:
- Follow the instructions for your operating system on the Google Cloud SDK installation guide.
Step 2: Initialize the SDK and Authenticate¶
-
Initialize the SDK and Authenticate (Optional):
- Open a terminal or command prompt.
- Initialize the SDK:
- Follow the prompts to authenticate with your Google account and set up your project.
-
Authenticate with Google Cloud:
Step 3: Create the CORS Configuration File¶
- Create a CORS Configuration File in Flutter project:
- Create a JSON file named
cors.json
with the following content: - This configuration allows requests from any localhost origin (with any port), and methods
GET
,POST
, andPUT
.
- Create a JSON file named
Step 4: Apply the CORS Configuration to Your Bucket¶
- Apply the CORS Configuration Using
gsutil
:- Use the
gsutil cors set
command to apply the CORS configuration to your Firebase Storage bucket. - Replace
your-bucket-name
with the name of your Firebase Storage bucket.
- Use the
How to Find
your-bucket-name
Using Firebase Console¶
- Open Firebase Console:
Go to the Firebase Console.
Select Your Project:
- Click on the project for which you want to find the bucket address.
Navigate to Storage:
- In the left-hand menu, click on "Storage".
View Bucket Details:
- You will see the default bucket listed at the top of the Storage page. The bucket address is typically in the format
your-project-id.appspot.com
.