Firebase 云功能:为 Firebase 数据库增值

Firebase Cloud function: add value to firebase database

每当任何文件添加到 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    
    });
});

条目在数据库中显示如下

我想要像下面这样的

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

奇怪,但也许这会起作用:

const filePath = object.name;
const newPostKey = admin.database().ref().push().key;   
admin.database().ref().update({
    [newPostKey] : filepath  
});

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

 admin.database().ref().child(newPostKey).set(filePath);