繁体   English   中英

I need to get the download URL from Firebase, Storage, using JavaScript, in html, The Picture gets uploaded, but I get no DownloadURL?

[英]I need to get the download URL from Firebase, Storage , using JavaScript, in html , The Picture gets uploaded , but I get no DownloadURL?

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数据库是我需要它来显示并且它会工作,但是当我 consolo.log const TASK 的快照时,我没有看到图像 URL 或下载 URL
我担心该方法:

const task = uploadBytesResumable(storeref, ImSRC, metdata)

我用来上传图片的图片不会生成图片 url? 会不会是这样?这是上传按钮的所有代码

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);
                    
            });
      }
});

从 Firebase 获取下载 URL 存储(就像上传数据本身一样)是一个异步操作。 就像在上传完成后需要运行的任何代码都需要在该任务的then()块内一样,在确定下载 URL 后需要运行的代码必须在then()任务也。

所以:

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);
                })  
        }            
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM