I want to store the download URL of an image as part of the post data, but am not able to do so, as the downloadURL is not stored in the imgURL variable. However, the downloadURL is able to print properly with console.log.
var postKey = firebase.database().ref('Posts/').push().key;
var imgURL = null;
uploadTask.snapshot.ref.getDownloadURL().then(function(downloadURL) {
imgURL = downloadURL;
console.log('File available at', downloadURL);
});
var updates = {};
var postData = {
url: imgURL,
caption: $("#imageCaption").val()
};
updates['/Posts/' + postKey] = postData;
firebase.database().ref().update(updates);