Download files from firebase and use it in the app

I have a PDF document stored on Firebase and it is just a tap button to preview the PDF,

Is it possible that instead of this PDF being opened from the firebase every time and needs internet connection , can it be downloaded instead on the device and access it from the local storage without need of internet connection. Thanks

There is a logic flow in the marketplace that “Download files”. Do an IF flow on button tap if the file has already been downloaded. If yes then open from there. If not then do the Download files flow to the specific file and save the file location to an on device data resource. And after that open the preview of the pdf.

is it like this? sorry I am still new using this platform

No. Now you seem to have two IF flows and none of them check for any condition. Both will return false and nothing will happen… This task is not for a beginner. I mean there is a lot of different things to consider. Wether it is android or ios, how to save the local file path etc… But I’ll try to give an idea:

I suggest doing these flows:

You have to search for most of these flows and install them first. Also this is a test case, so I just have a page variable named fileUrl which should be changed to anything that contains your download url that you want to preview.

First we have to check if it is already downloaded. I used the “documents” folder, as that seems to be the same for both systems. So we will check if a document with the same name as the file from the download url can be found in the documents folder:

The formula in the properties tab is:

systemVars.fileSystem.directories.document+"/"+SPLIT(SPLIT(pageVars.fileUrl, "/o/")[1], "?")[0]

This splits the download url into 3 different parts, and gets the name of the uploaded file and adds that to the system directory path to find the file.
This flow returns a true / false value. So we can check for that in the IF flow:

If true, then it has already been downloaded so we can open the preview.:

Here use the same formula as the one that we used in the does the file exist flow.

If the file has not yet been downloaded then we need to download it:

These are the settings of the download files flow… On default it downloads to the downloads folder, but we want to make sure that the file is in the same folder which we want to check next time. So we have to move the file into that folder. This is why we need the “Move/rename file/directory” flow:

The formula here for the “source path” is:

outputs["Download files"].files[0].path

and for the target path is:

systemVars.fileSystem.directories.document+"/"+outputs["Download files"].files[0].name

If this flow throws an error, that is likely to happen if the directory yet doesn’t exist, we have to create the directory and retry the move file flow. This happens here:



After we moved the file we can again use the preview file flow and it will now show from the local storage…

*Just a friendly reminder, if You are a new user, please read the

*That has pretty decent information on all the flow formulas that are available and how to use them.

1 Like

thank you so much for help :innocent: