我需要从firebase,存储,使用javascript,在html中获得下载URL,图片上传,但是我没有下载吗?

发布于 2025-02-12 07:41:58 字数 1108 浏览 0 评论 0原文

当我敲打上传图片时,将图片上传到firebase存储,但是我似乎无法获取图像URL,我可以转到firebase上的“存储”选项卡,然后单击图像,然后单击其ling,将链接复制到其中,然后经过它数据库是我需要显示的,并且它将起作用,但是当我consolo.log const任务快照时,我看不到图像URL或下载URL!
我担心这种方法:

const task = uploadBytesResumable(storeref, ImSRC, metdata)

IAM用来上传图像不会产生图像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);
                    
            });
      }
});

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

污味仙女 2025-02-19 07:41:58

从firebase存储中获取下载URL是(就像上传数据本身)一个异步操作。就像上传完成后需要运行的任何代码一样然后() 任务的块。

所以:

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);
                })  
        }            
});
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文