Set Up Cloud Firestore
Last Updated: 27 May 2024Step 1: Get your Cloud Storage Bucket name for Firebase
Go to Firebase Console > Storage
Here, you will find your cloud storage bucket link for your Firebase Project. Copy that link.
Step 2: Install gsutil
On Windows
- Install gsutil using the Cloud SDK Installer > https://dl.google.com/dl/cloudsdk/channels/rapid/GoogleCloudSDKInstaller.exe
- Before Finishing installation, make sure that the following are selected:
- Start Google Cloud SDK Shell
- Run 'gcloud init'
A Google Cloud SDK Shell terminal will appear. Let it initialize and then this line will appear:
To continue, you must login. Would you like to login (Y/n)?
Press Y
to Sign In.
On other Operating Systems
- Install gsutil, follow this guide > https://cloud.google.com/storage/docs/gsutil_install#mac
Step 3: Set cors.json
- Download this cors.json file: Download cors.json
- Navigate to your Cloud SDK directory.
- Paste the cors.json file at this location
- Open Cloud SDK Shell Terminal and run this command:
gsutil cors set cors.json gs://<YOUR_CLOUD_STORAGE_BUCKET>
What is cors.json?
CORS (Cross-Origin Resource Sharing) can be simply defined as rules that allow or block access to specified domains.
The cors.json file that you downloaded earlier allows access to any domain:
[
{
"origin": ["*"],
"method": ["GET"],
"maxAgeSeconds": 3600
}
]
The asterisk "*" means that it will allow access to any domain. You can replace it with your own domain name and then run the gsutil cors set to apply the CORS.
Firebase Storage Rules
The default rules will allow to Upload or Download data only if the user is Signed In using Authentication.
Temporarily, for Testing Purposes, you can allow uploads and downloads even if user is not Authenticated using these rules given below:
rules_version = '2';
service firebase.storage {
match /b/{bucket}/o {
match /{allPaths=**} {
allow read, write;
}
}
}
This will make your database public (insecure), so anyone can get or modify any data. These rules are preferred when you are still developing your app.
If you are going to publish your app, you will need proper Security Rules to protect your database. To do so, check out this Doc:📄Secure Your Firebase Project.