Reputation: 199
I have tried different values of once() and then() but I seem to get a similar error. The current error message is:
"DataSnapshot.val failed: Was called with 1 argument. Expects none"
I am using firebase as my database and I'm trying to withdraw an encrypted image from it under the field of ('Canvas'). Here is my code
//DECRYPT IMAGE
var decrtpt, img;
function decryptImg(){
firebase.database().ref('Cords/' + img).on('value', function(snapshot){
decrypt = snapshot.val('Canvas')
console.log(decrypt);
});
}
What do I need to do to fix this error. So that I can decrypt the string so I can use the image, many thanks :) I am using JavaScript just in case you did not know.
Upvotes: 1
Views: 340
Reputation: 23170
snapshot.val()
doesn't accept any argument.
If you attach an async callback to read the data at your 'Cords/' + img
reference, you can receive the data using snapshot.val()
. If the data is an object and you want to get the value by key, you can do it like this:
function decryptImg(){
firebase.database()
.ref('Cords/' + img)
.on('value', function(snapshot){
const image = snapshot.val()
console.log('Canvas: ' + image.Canvas)
})
}
For more info check https://firebase.google.com/docs/database/admin/retrieve-data#node.js
Upvotes: 2