Whenever any file added to firebase storage, it's path value should be stored in firebase database by firebase cloud function
I have achieved by following code
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
});
});
Entry is showing in database like below
I want it like below
I have tried a lot but could not be able to achieve it, will any body help me where should I need to change so I can achieve code like I want
Thanks to @DoesData finally I have achieved by following way
admin.database().ref().child(newPostKey).set(filePath);
Strange, but maybe this will work:
const filePath = object.name;
const newPostKey = admin.database().ref().push().key;
admin.database().ref().update({
[newPostKey] : filepath
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With