Simon
Simon

Reputation: 2538

Letting user export their data from Firebase database?

I have a pretty run of the mill Firebase database, and I'd like the user to be able to export their data in JSON format. I noticed that if you go into the realtime database console on Firebase the admin can export as JSON, so I'm curious if it would be possible to have some sort of URL that the user can access if they are authenticated in order to be able to retrieve their own user data..

Any ideas?

Thanks

Upvotes: 0

Views: 140

Answers (1)

Alex Mamo
Alex Mamo

Reputation: 139019

I once developed an application with an option that allows the user to export the data to a txt file on the device storage. So if you think that this option can help you, please use the following code:

try {
    File root = new File(Environment.getExternalStorageDirectory(), "myFolder");
    if (!root.exists()) {
        root.mkdirs();
    }
    File myFile = new File(root, "myFileName.txt");
    FileWriter writer = new FileWriter(myFile);
    writer.append(text);
    writer.flush();
    writer.close();
} catch (IOException e) {
    e.printStackTrace();
}

You might want to change the name of the folder that will be created to store all of your exported txt files from myFolder with a particular one. You might also want to change the filename myFileName with a particular one.

Hope it helps.

Upvotes: 1

Related Questions