This is where I want to save all the data that I receive from Firebase, in such a way that this file contains everything from the firebase database and is updated once the user logs in/ refreshes.
This data will the be used and referenced like any other data.json in assets.
Any help would be appreciated
why not just download the whole .json file from firebase hosting? upload your .json file to firebase hositng (free) and let your app download the file on iniit.
https://www.npmjs.com/package/cordova-plugin-file-downloader
but I’m curious why you should be doing this. a Json file is only few kb at best… why don’t you include it in your app?
Thanks for the resource. I’ll try the solution as suggested and will let you know if it is what I wanted.
The reason I want the data to be on Firebase is, so that any changes can directly be reflected to all the users. And having an already ready program with providers that work for a JSON file, I was wondering if it’s possible to download the JSON from firebase everytime the user logins, hence updating the contents as displayed.
In essence, the app would http fetch data from a project file, and this file is updated with the JSON from Firebase.
I’m guessing your solution would work the other way around. Whereas here I want that data.json/csv to be updated from the data from Firebase. Doesn’t necessarily have to be assets folder though, as I’m guessing the assets folder is read-only at runtime
this.platform.ready().then(() => {
cordova downloader downloads a json file from your firebase host
}
but if you’re looking to just save input data, you can save it to SQlite storage as well…
I’m really stuck here. Could you please help me know the libraries/ plugins to be imported
I’vs done this:
import { FileTransfer, FileTransferObject } from '@ionic-native/file-transfer';//
import { File } from '@ionic-native/file';//
In NgModule Providers:
FileTransfer,
FileTransferObject,
File
In the root page’s .ts:
fileTransfer: FileTransferObject = this.transfer.create();//
ionViewDidLoad() {
....
//downloader.init({folder: "testApp", unzip: true});
//downloader.get("http://yourhost.de/some.zip");
this.download();
}
download() {
console.log("Inside!");
const url = 'https://_project-name_.firebaseio.com/';
this.fileTransfer.download(url, this.file.dataDirectory + 'file.json').then((entry) => {
console.log('download complete: ' + entry.toURL());
}, () => {
console.log("Error");
// handle error
});
}//
For some reason, there seems to be no errors but I don’t get any output in the console
well the documentation indicates you have to use file’s directory (including file name) as url.
so try:
https://-your-project-name.firebaseio.com/your-jsonfile-name.json
as your url.