I am trying to upload image in firebase storage. Photo is uploaded, but I can't get the url. I got the source code from firebase, so I think my code is right but I don't no why this is happening. Could anyone please tell me how can I get the url?
My code is here:
firebase.initializeApp(firebaseConfig);
firebase.analytics();
var file = document.querySelector("#file").value;
const storageRef = firebase.storage().ref();
function uploadFile() {
var file = document.getElementById('file').files[0];
var uploadTask = storageRef.child('images/' + file.name).put(file);
uploadTask.on('state_changed',
(snapshot) => {
var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
alert('Upload is ' + progress + '% done');
switch (snapshot.state) {
case firebase.storage.TaskState.PAUSED:
alert('Upload is paused');
break;
case firebase.storage.TaskState.RUNNING:
alert('Upload is running');
break;
}
},
(error) => {
},
() => {
uploadTask.snapshot.ref.getDownloadURL().then((downloadURL) => {
alert(downloadURL)
document.getElementById('image').src = downloadURL;
alert('File available at', downloadURL);
});
}
);
}