Import json file from Firebase Admin SDK

后端 未结 1 753
北荒
北荒 2021-01-16 03:14

I can update the whole database (Real Database) by importing a json file in Firebase Console:

How can I do it programmatically from server side (with Fireba

相关标签:
1条回答
  • 2021-01-16 03:22

    Solved it:

    private void uploadFirebaseDatabaseFile(Gson gson, JsonObject jsonObject) throws Exception {
        // As an admin, the app has access to read and write all data, regardless of Security Rules
        DatabaseReference ref = FirebaseDatabase.getInstance().getReference();
        CountDownLatch done = new CountDownLatch(1);
        // we must convert our JsonObject and its all nested children to Map<String, Object>
        ref.setValue(gson.fromJson(jsonObject, Map.class), (error, ref1) -> {
                System.out.println(error + " " + ref1);
            done.countDown();
        });
        done.await();
    }
    
    0 讨论(0)
提交回复
热议问题