RealTime Database, user authenticator and hosting to make application development easier. It provides web app and mobile app developers with a way to link their applications to back-end cloud storage. I'm trying different BaaS alternatives as Parse.com is shutting down by the end of the year. Luckily for us, we have a really cool alternative: Firebase . Firebase is a unified app platform for Android, iOS and mobile web development. It featuresandto make application development easier. It provides web app and mobile app developers with a way to link their applications to back-end cloud storage.





In this article I will show you how I interact with the Firebase RealTime Database via the REST API to stream files in JSON format using the latest Delphi 10.1 Berlin update 2.





POC and it will allow you to upload a pdf file via the desktop application, marshall its content into JSON format and then send it via POST to the JSON format and then transformed back into pdf format. The following diagram explains the process in detail: The following example is just aand it will allow you to upload afile via the desktop application, marshall its content intoformat and then send it via POST to the Firebase Database URL Rest end-point . Then the files are accessed with the (Android) mobile version of it where files are unmarshalled via HTTP Response intoformat and then transformed back intoformat. The following diagram explains the process in detail:

The following code shows how to stream the file into JSON format using the TDBXJSONTools.StreamToJSON method:





And to translate it back to a file stream:



The source code of the project can be found on my github repository:

In this repository you will find simple examples using different vendors like Parse.com, Kinvey and Firebase, exploring different alternatives using HTTP Rest. You can read my previous articles about this topic here:

To use the Firebase Database URL as an end-point you just need to append .json to the end of the URL and send a request from our HTTPS component. For this example, I've created a project in Firebase called delphitestproject. Each request needs to be authenticated and the easiest way to achieve that is by attaching the apiKey from Firebase to your request. There are other options to authenticate your requests but these require exploring in deep firebase service accounts.





To get the apiKey, go to Settings -> Project Settings -> General, and you will see there the web API Key:





You can test your end-point using curl to simulate the requests:





The process to upload a file works as follows:



And the same solution running on my android and then opening the file from there as it has been downloaded from the cloud:



The Delphi app uses the the latest PPL (

When opening files on the Android app, I had to use Android intents to call the correct pdf component. The solution is still incomplete as I need to find a good way to browse files on my Android device and upload this one in the cloud database. From here onward, the sky is the limit. You could streamline the process by storing file Ids so then the whole content is not downloaded every time (which increases bandwidth usage) and encrypt your pdf files prior to streaming them to the cloud for an additional layer of security.



Remember to explore the source code for more. Enjoy!



Jordi And the same solution running on my android and then opening the file from there as it has been downloaded from the cloud:The Delphi app uses the the latest PPL ( Parallel programming Library ) to avoid freezing the UI. There are separate TTask that are called for the GET/POST request so there is no call in the UI Thread.When opening files on the Android app, I had to use Android intents to call the correct pdf component. The solution is still incomplete as I need to find a good way to browse files on my Android device and upload this one in the cloud database. From here onward, the sky is the limit. You could streamline the process by storing file Ids so then the whole content is not downloaded every time (which increases bandwidth usage) and encrypt your pdf files prior to streaming them to the cloud for an additional layer of security.Remember to explore the source code for more. Enjoy!

Share This:

Firebase will store your documents in the Firebase Database in JSON format: