I am trying to assign the download url to a variable but it's not applying it. The variable is outside the function so not sure where I am going wrong. I essentially want the download url string so I could use it for reference.
var img_path;
var upload_path;
if (img.length != 0){
var imageFile = img[0];
var imageName = imageFile.name;
img_path = ‘/some-path/’ + imageName;
//upload image
let storageRef = firebase.storage().ref(img_path);
storageRef.put(imageFile).then((savedPicture) => {
storageRef.getDownloadURL().then(function(downloadURL) {
console.log('File available at', downloadURL);
upload_path = downloadURL;
});
});
//returns undefined
console.log(upload_path);