When I hit upload the picture gets uploaded to firebase Storage, but i cant seem to get the image url, I can go to the Storage tab on firebase click on the image and click on its ling , copy the link in and then past it into the DATABASE were i need it for display and it will work, But i dont see an image URL or A download URL when i consolo.log the snapshot of the const TASK!
I fear that the method:
const task = uploadBytesResumable(storeref, ImSRC, metdata)
that iam using to upload the image does not produce an image url! Could This be So? !!!HERE IS ALL THE CODE FOR THE UPLOAD BUTTON !!
Upload.addEventListener('click', (e) =>{
let ImSRC = files[0];
if(ImSRC == null ){
alert('no picture selected');
}else{
const metdata = {
contentType: ImSRC.type
}
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
})
}
console.log(ProPicUrl);
});
}
});
Getting the download URL from Firebase Storage is (like uploading the data itself) an asynchronous operation. Just like any code that needs to run after the upload has completed needs to be inside the then() block for that task, the code that needs to run after the download URL has been determined has to be inside the then() block for that task too.
So:
const storeref = sRef(storage,"UsersProPic/" + cUserID);
const task = uploadBytesResumable(storeref, ImSRC, metdata).then((snapshot)=>{
console.log(snapshot);
function getData(){
snapshot.getDownloadURL().then(function(url){
ProPicUrl = url;
console.log(ProPicUrl);
})
}
});