We've recently created a GCP project and a Cloud Storage bucket in it.
Then we decided to use Firebase to host our React app. However, after creating the Firebase project (Why did we need to create a new project?), we got a different storage bucket. And it seems that it's not possible to view the same bucket from both projects.
Our backend uses a Cloud Storage bucket. Our frontend sends files to a Firestore bucket, which is different. How can we link it together?
It's important to know that a Firebase project IS a Google Cloud project. Read more about that in this blog. Firebase is essentially a layer of APIs and services in a Google Cloud project. What you probably should have done in the first place is add Firebase to your existing Cloud project, but it's probably not worthwhile to do that if you already have an existing Firebase project.
There's really no way to link the projects together that would be convenient for you. What I recommend you do is abandon your first Cloud project, and copy the contents of your first bucket into your Firebase project default bucket. Also read more about the relationship between Firebase and Google Cloud with respect to Cloud Storage in this blog.
You can use Firebase storage's getStorage function to specify the Google Cloud Storage Bucket. Then use gsutil to add the appropriate permissions between your Firebase project and the GCS bucket. You may need to edit the bucket permissions by going to Storage > Buckets and selecting Edit Bucket Permissions from the kebab menu (⋮) right of the bucket name. Here, you add can add the service-#gcp-sa-firebasestorage.iam.gserviceaccount.com
Frontend/browser Firebase code:
import { getApp } from "firebase/app";
import { getStorage } from "firebase/storage";
const firebaseApp = getApp();
const storage = getStorage(firebaseApp, "gs://my-custom-bucket");
command line to add permissions:
gsutil -m acl ch -r -u service-<project number>#gcp-sa-firebasestorage.iam.gserviceaccount.com gs://<my-custom-bucket>
The service-project number can be found in the Firebase project's console, under settings.
Related
I want to transfer data in Firestore in a Firebase project to Firestore in another (GCP only) project.
What is the best solution for the this work?
Does the document ID change after transfer?
Project one:
Google Cloud console > firestore > Import/Export > Export
get a export the firestore data into the Storage bucket.
Google Cloud console > Cloud Storage > select bucket
download the export firestore folder
Project two:
Google Cloud console > Cloud Storage > select bucket
upload the export firestore folder
Google Cloud console > firestore > Import/Export > Import
import the firestore data into the Storage bucket.
Does the document ID change after transfer?
Documents ID did not change.
To move Cloud Firestore data from one project to another project you have to follow the following 4 steps -
Create a Cloud Storage bucket to hold the data from your source project
Export the data from your source project to the bucket.
Give your destination project permission to read from the bucket.
Import the data from the bucket into your destination project.
The data in the destination project remains as it is in the source project and specifically to answer your question, the document ID does not change after transfer.
To know the detailed process on how to move Cloud Firestore data from one project to another project you can follow this document.
Firebase Firestore and Google Cloud Firestore are the same thing. Firebase just provided client SDK and has security rules while Google Cloud mostly has server side SDKs. You can view the both Firebase console and Google Cloud console.
Also checkout this article for detailed information.
I have a situation where I'm trying to enable Firebase Storage but also have an App Engine deployment which already created the buckets {project_name}.appspot.com and it give me the following error message:
I'm aware you can change the Firebase bucket after enabling Firebase Storage from the Firebase console, however I don't see a way to do it before/while enabling Firebase Storage.
I'm working with a few restrictions and want to see if I can enable Firebase storage with those. My first restriction is that I cannot create a separate GCP project for this. We have billing credits which are linked to the project. Another is that I cannot change the App Engine configuration, or rather doing so will only be done in the worst case since that's already being used for a production workload. Lastly, our parent organization is pretty strict in terms of their Org policies and is likely not willing to change it.
Is there a way specify a different bucket to enable Firebase Storage to avoid the conflict?
I created a GCP project with an App Engine app and a Firebase project with Firebase Storage enabled. According to the documentation these services require a default resource location in order to be initially provisioned. Firebase Storage makes use of the same default bucket as App Engine to initialize. It appears that your organization might have blocked access to this bucket, which makes Firebase Storage not to work initially. You should request the organizational policies to be temporarily allowed while Firebase Storage is provisioned, and then, as you mentioned, you can change the bucket used by Firebase Storage to a different one. Firebase makes use also of the following Storage service account:
You should make sure that this account has permissions to perform its operation at creation time of the bucket, from the FAQ it also explains this is needed:
Cloud Storage for Firebase creates a default bucket in the App Engine free tier.
I'm following the official docs on how to export and import firebase firestore data between 2 projects.
I'm able to export firestore data to a bucket. https://console.cloud.google.com/firestore/export
But I don't see that bucket when I try to import in a different firebase project. https://console.cloud.google.com/firestore/import
I gave Storage Admin permission to the destination service account i.e. dest-proj#appspot.gserviceaccount.com and both projects and this bucket is stored in the same multi-region (us-centeral)
I'm aware of the other way to import-export using gcloud shell but why this method is not working?
The console only browse buckets that exist inside your current project. If data is coming from an outside bucket, you can simply type its entire file path in the Filename field as shown on the image below.
It will succeed if the service account running the import have the right IAM permission on the separate source bucket.
The page https://firebase.google.com/docs/storage/web/upload-files tells nearly everything about uploading files to Firebase storage from a web client. Except that it has no information about buckets. The examples all uses the default bucket.
If I have another bucket in my Firebase-project, can I upload to that somehow?
Yes, you can do that. There is a bucket import mechanism in the Firebase Storage console hidden behind the three-dots overflow menu. I believe you can then reference it by initializing a new Firebase App instance using initializeApp, providing the name of that bucket in the options.
Is it possible to setup a Firebase cloud function that serves a file from a Firebase cloud storage bucket to avoid using the long firebasestorage.googleapis.com link
Yes, that is possible. In that case you can even go without download URLs, since in Cloud Functions you'll have administrative access to all files in your Cloud Storage bucket anyway.