2017-10-10 34 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

相關問題