You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/troubleshooting/firebase-issues/configuring_cors_for_firebase_storage.md
+29-12Lines changed: 29 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -32,36 +32,53 @@ Follow these steps to configure CORS for your Firebase Storage bucket:
32
32
gcloud config set project <your-project-id>
33
33
```
34
34
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`:
36
38
37
39
```jsx
38
-
cd gs://<your-bucket-name>
40
+
"origins": ["https://www.example.com"]
39
41
```
40
42
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:
42
44
43
45
```jsx
44
-
gsutil cors set cors.json gs://<your-bucket-name>
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.
48
50
49
51
```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
+
]
51
59
```
52
60
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.
54
62
55
-
```jsx
56
-
"origins": ["https://www.example.com"]
57
-
```
63
+

58
64
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.
You should see the same allowed origins and any other info defined in your `cors.json` file.
81
+
65
82
For more information on configuring CORSin Firebase Storage, please see the **[official documentation](https://firebase.google.com/docs/storage/web/download-files#cors_configuration)**.
0 commit comments