2017-10-10 44 views
0

我对下面的代码有问题。我正在用相机拍照,然后将图像上传到Firebase存储。不过,我也将其他数据添加到数据库,它也包含照片网址。上面的脚本开始将图像上传到存储器,但代码的另一部分将不起作用,因为只有在上传过程完成后,this.picurl才会具有值。仅当图像上传完成时才上载附加数据(序列号?)

如何添加序列,以便当this.picurl = savepic.downloadURL最终可用时(图像上传成功),其余代码将运行。

adatfeltolt() { 
    this.mypicref.child(this.uid()).child('pic.jpg') 
    .putString(this.picdata, 'base64', { contentType: 'image/jpg' }) 
    .then(savepic => { 
     this.picurl = savepic.downloadURL 
    }) 
     this.firebasedb.list("/fogasok/").push({ 
     datum:this.fogasDatuma, 
     //halfaj:this.fogasHalfaj, 
     suly:this.fogasSuly, 
     egyeb:this.fogasEgyeb, 
     keplink:this.picurl 
    }); 

    } 

回答

0

你可以把你的firebase.list块到当时的回调,也可以使用异步/等待这样做:

async adatfeltolt() { 
    let savepic = await this.mypicref.child(this.uid()).child('pic.jpg').putString(this.picdata, 'base64', { contentType: 'image/jpg' }) 
    this.picurl = savepic.downloadURL; 
    this.firebasedb.list("/fogasok/").push({ 
    datum: this.fogasDatuma, 
    //halfaj: this.fogasHalfaj, 
    suly: this.fogasSuly, 
    egyeb: this.fogasEgyeb, 
    keplink: this.picurl 
    }); 
} 
+0

谢谢大卫:) – Thomas

相关问题