【发布时间】:2018-02-17 13:13:10
【问题描述】:
当任何文件添加到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
});
});
条目显示在数据库中,如下所示
我想要像下面这样
我已经尝试了很多但无法实现它,任何人都可以帮助我在哪里需要更改以便我可以实现我想要的代码
【问题讨论】:
-
记录filePath时打印什么?只是网址?试试 admin.database().ref().child(newPostKey).set(filePath);
-
非常感谢@DoesData
标签: firebase firebase-realtime-database google-cloud-functions