Firebase Cloud 功能:为 Firebase 数据库添加价值

Sid*_*mit 4 firebase firebase-realtime-database google-cloud-functions

每当将任何文件添加到 firebase 存储时,它的路径值都应通过 firebase 云函数存储在 firebase 数据库中

我已经通过以下代码实现

const functions = require('firebase-functions');

const admin = require('firebase-admin');
admin.initializeApp(functions.config().firebase);

exports.generateThumbnail = functions.storage.object().onChange(event => {
    const object = event.data;
    const resourceState = object.resourceState;
    // Exit if this is a move or deletion event.
    if (resourceState === 'not_exists') {
      console.log('This is a deletion event.');
      return;
    }
    const filePath = object.name; // File path in the bucket.
    console.log(filePath);

    const newPostKey = admin.database().ref().push().key;   

    admin.database().ref().child(newPostKey).set({
        filePath    
    });
});
Run Code Online (Sandbox Code Playgroud)

条目显示在数据库中,如下所示

在此处输入图片说明

我想要它像下面

在此处输入图片说明

我已经尝试了很多但无法实现它,任何机构都可以帮助我我应该在哪里进行更改,以便我可以实现我想要的代码

Sid*_*mit 6

感谢@DoesData,我终于通过以下方式实现了

 admin.database().ref().child(newPostKey).set(filePath);
Run Code Online (Sandbox Code Playgroud)