Realtime Database Stores and sync app data in milliseconds
Google Drive is one of the best file sync apps that let you store all of your files online alongside your Google Docs documents, and keep them synced with all of your devices.Google Drive Integrations
Google Drive + DropboxCopy new Google Drive files in a specific folder to Dropbox Read More...
Google Drive + DropboxCopy new Google Drive files in any folder to Dropbox Read More...
Google Drive + Google SheetsAdd rows on Google Sheets spreadsheet when a file is added in a Google Drive folder Read More...
Google Drive + Google CalendarGenerate new Google Calendar events for new files on Google Drive Read More...
It's easy to connect Firebase Realtime Database + Google Drive without coding knowledge. Start creating your own business flow.
Triggers on updation of a child object in firebase realtime database.
New Child Object in a Firebase Realtime Database
Triggers whenever a new file is added to any of the folders.
Triggers whenever a new file is directly added to a specific folder.(but doesn't trigger when a file is added to the subfolders)
Creates or replaces a child object within your Firebase Realtime Database.
Create a new file from plain text.
Create a new folder.
An existing file is copied to Google Drive from a different service.
Firebase Realtime Database is a cloud-hosted database. It lets you store and sync data as key-value pairs in realtime. This means that the data you write to the database immediately reflects in the UI of your app, and vice versa.
Google Drive is a free space where you can store all types of files. It is a cloud storage service by Google and it allows users to save documents, images, videos, and other files online. With Google Drive, you can easily share your files with friends or workgroups. You can also use Google Drive to back up your files.
In this section, I will talk about how we can integrate Firebase Realtime Database with Google Drive. We will use React to accomplish this integration.
First of all, we need an index.html file inside the src fpder for our React App. In this file, we will include all the required scripts like react.js, firebase.js and googleapis.js. After including all the scripts, we will create a FirebaseApp variable because we will need to use it in our React component later. We will get a Firebase App instance by calling the Firebase constructor and passing it our FirebaseApp variable as a parameter.
Now that we have a Firebase app instance, we can use the initApp method provided by Firebase SDK to initialize our app with a reference to our database URL such that we can access it later on in our app. This initialization will return a promise which when respved will give us an initial config object.
Next, we will include a login button to load the Google Sign-in popup so that the user can authenticate themselves before accessing their Google Drive files from our app. We will implement the logic for this button in our callback function which accepts a signInSuccessful parameter as its only argument. The signInSuccessful parameter argument will be true if the user has successfully signed in and false otherwise. If the user has signed in successfully, then we will show them a modal with a list of their files from Google Drive. After showing the modal, we will pass the signInSuccessful parameter to our openFileList function as an argument so that the openFileList function can update its state according to the value of signInSuccessful .
The openFileList function requires two other functions as arguments named openFileById and openFileByName . The openFileById function takes a fileId parameter whose value is set by calling getFileById on our config object returned earlier from the Firebase initApp method whenever the user clicks on a file from the Google Drive modal page. The openFileByName function takes a filename parameter whose value is set by calling getFileByName on our config object whenever the user clicks on a file from Google Drive via the Google Drive modal page.
Both getFileById and getFileByName methods return promises which are respved once their respective request has completed. If a request fails for any reason, then its promise is rejected with an appropriate error message. Once these requests complete successfully or fail, they call their respective success or error callback functions with 2 parameters sent from the server. a responseText and responseCode . The responseText contains the contents of the requested file’s JSON representation while responseCode contains any HTTP status codes returned by the server (for example 200 or 404. In our openFileById and openFileByName callback functions, we are just logging out these response parameters so that we can understand what’s going on in them when they are called from our app in future. We are also setting the loadedFile variable to true so that we can show the file’s name in our modal later on when it is loaded by Firebase Storage SDK.
Lastly, we are defining our HomePage React component class which extends React Component . In the constructor, we pass in an array of file names and chooseRandomFile as props so that we can show these files’ names on our HomePage React component class’s render function. We also pass in an updateFirebaseStorageStatus(. function as well as an onClick event handler for each file name such that they can call their respective callback functions when clicked on. The updateFirebaseStorageStatus(. function takes a status parameter whose value is either loading or loaded , depending on whether or not the requested file is currently being loaded by Firebase Storage SDK. We use this value to contrp the values of two different states of our component. loading and loaded . The loading state gives focus to the button which calls getFileByName while the loaded state gives focus to the button which calls openFileById . By using these two states, you allow your users to modify their actions based on whether or not they think that their action will result in an immediate result or if they should wait until something happens first before acting upon their intentions. For example, if they click on a video file from Google Drive when your app is in its loading state then they will not be able to play it since it isn’t fully loaded yet; however, if they click on a video file from Google Drive when your app is in its loaded state then they will be able to play it since it will be fully loaded already at that point in time after pressing play . The onClick event handler gets passed 3 arguments. an event , fileName , and index respectively. When a fileName is clicked on, we call getFileByName passing it the name of that file name as well as an empty array because its callback function expects an array of responseText s instead of just one responseText . Then, we append the responseText s returned by getFileByName into an array named filesOfUser and then send that array through props to HomePage React component class’s render function so that it can show all of those individual files’ names within its render function. Likewise, when a index is clicked on, we call openFileById passing it that particular index as well as an empty array because its callback function expects an array of responseText s instead of just one responseText . Then, we append the responseText s returned by openFileById into an array named responses array and then send that array through props to HomePage React component class’s render function so that it can show all of those individual responseText s within its render function. Lastly, we call updateFirebaseStorageStatus passing in either loading or loaded depending on whether or not a particular responseText is from Firebase Storage SDK or not. Doing so allows us to keep track of whether or not there is currently something happening in Firebase Storage SDK with respect to any of these files’ data so that we can appropriately show this information to our users via updating our HomePage React component class’s state with whatever information we want them to see at any given moment in time. For example, if they click on a video file from Google Drive when your app is in its loading state then they will check back again once your app is in its loaded state since Firebase Storage SDK hasn’t finished uploading their video file yet; however, if they click on a video file from Google Drive when your app is in its loaded state then they could play it since Firebase Storage SDK has already finished uploading their video file by that time since it was fully loaded already at that point in time after pressing play .
After defining our HomePage React component class, we create an App component class which extends React Component . This App component class requires two other components. HomePage and FirebaseStorageInfo . We pass HomePage into App ‘s constructor as well as an updateFirebaseStorageStatus(. function as prop so that homePage ‘s updateFirebaseStorageStatus(. callback function can call updateFirebaseStorageStatus(. whenever needed. Similarly, we pass FirebaseStorageInfo into App ‘s constructor as well as an updateFirebaseStorageStatus(. function as prop so that fireBaseStorageInfo ‘s updateFirebaseStorageStatus(. callback function can call updateFirebaseStorageStatus(. whenever needed too. Lastly, we call HomePage ‘s render(. method in App ‘s render(. method so that HomePage ‘s render(. method returns whatever HomePage ‘s state looks like at any given moment in time based on what page is currently being rendered (loading or loaded . by App ‘s render(. method due to whatever reason (such as user clicking on a button etc..
After creating App , we create AppContainer React component class whose render(. method returns
The process to integrate Firebase Realtime Database and Google Drive may seem complicated and intimidating. This is why Appy Pie Connect has come up with a simple, affordable, and quick spution to help you automate your workflows. Click on the button below to begin.