每当将任何文件添加到 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
});
});
条目显示在数据库中,如下所示
我想要像下面这样
我已经尝试了很多但无法实现它,任何机构都可以帮助我我应该在哪里进行更改,以便我可以实现我想要的代码
最佳答案
感谢@DoesData,我终于通过以下方式实现了
admin.database().ref().child(newPostKey).set(filePath);
关于Firebase 云函数 : add value to firebase database,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46119369/