Skip to content

Commit f4493b2

Browse files
updated Firebase CORS steps
1 parent 3ddc41f commit f4493b2

File tree

2 files changed

+29
-12
lines changed

2 files changed

+29
-12
lines changed
88.8 KB
Loading

docs/troubleshooting/firebase-issues/configuring_cors_for_firebase_storage.md

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,36 +32,53 @@ Follow these steps to configure CORS for your Firebase Storage bucket:
3232
gcloud config set project <your-project-id>
3333
```
3434

35-
4. **Navigate to your Firebase Storage bucket:**
35+
4. **Define and upload your cors.json file:**
36+
37+
The `cors.json` file contains a list of origins that are allowed to access your resources. Each origin is a string that identifies a domain or port. For example, the following origin allows access from the domain `www.example.com`:
3638

3739
```jsx
38-
cd gs://<your-bucket-name>
40+
"origins": ["https://www.example.com"]
3941
```
4042

41-
5. **Run the `cors` Command to Configure CORS:**
43+
You can also specify a list of allowed headers. The following example allows access to the `Content-Type` and `Authorization` headers:
4244

4345
```jsx
44-
gsutil cors set cors.json gs://<your-bucket-name>
46+
"origins": ["https://www.example.com"], "allowedHeaders": ["Content-Type", "Authorization"]
4547
```
4648

47-
You can also specify a list of allowed headers by running the following command:
49+
To allow any origin to access your resource, you can use `*`. The `cors.json` file below allows any origin to access, but not modify your resources.
4850

4951
```jsx
50-
gsutil cors set cors.json gs://<your-bucket-name> --allowed-headers="Content-Type, Authorization"
52+
[
53+
{
54+
"origin": ["*"],
55+
"method": ["GET"],
56+
"maxAgeSeconds": 3600
57+
}
58+
]
5159
```
5260

53-
The `cors.json` file contains a list of origins that are allowed to access your resources. Each origin is a string that identifies a domain or port. For example, the following origin allows access from the domain `www.example.com`:
61+
Once you have defined your `cors.json` file, upload it to Google Cloud Console.
5462

55-
```jsx
56-
"origins": ["https://www.example.com"]
57-
```
63+
![](../assets/uploadToGCC.png)
5864

59-
You can also specify a list of allowed headers. The following example allows access to the `Content-Type` and `Authorization` headers:
65+
To confirm that you have uploaded it correctly, you can run `ls` in your console and you should see your `cors.json` file listed.
66+
67+
68+
5. **Run the `cors` Command to Configure CORS:**
6069

6170
```jsx
62-
"origins": ["https://www.example.com"], "allowedHeaders": ["Content-Type", "Authorization"]
71+
gcloud storage buckets update gs://your-bucket-name --cors-file=cors.json
6372
```
6473

74+
6. **(Optional) Confirm success by viewing the CORS of your bucket**
75+
76+
Run the following command to confirm that the rules from your `cors.json` file were applied.
77+
```jsx
78+
gcloud storage buckets describe gs://YOUR_BUCKET_NAME --format="default(cors_config)"
79+
```
80+
You should see the same allowed origins and any other info defined in your `cors.json` file.
81+
6582
For more information on configuring CORS in Firebase Storage, please see the **[official documentation](https://firebase.google.com/docs/storage/web/download-files#cors_configuration)**.
6683

6784

0 commit comments

Comments
 (0)