2017-02-13 118 views
0

我正在使用Ionic 2創建應用程序,其中一個功能是更新頭像。典型的東西。當用戶更新頭像時,必須下載新頭像。重新加載存儲在Firebase存儲中的圖像的最佳方式#askfirebase

這怎麼辦?是否有事件(在上傳完成後重新獲取圖像)還是隻在上傳後重新獲取圖像?

+0

也許你可以添加監聽器化身網址爲每個用戶的價值,你取 – yarin

+0

我需要一個事件來讓我知道上傳已完成 – Xerri

回答

1

你只需要使用你調用的方法的返回promisse來保存你的新的個人資料圖片。

firebase.storage().ref('/ProfilePictures/').putString(MyPicBase64String, 'base64', { contentType: 'image/png' }).then((pic) => { 
    let newPic = pic.downloadURL; // save in a new var, a global var, your sql/localStorage, the var in your <img />, etc 
}); 

如果您需要單獨做到這一點,你可以調用.getDownloadURL()方法

firebase.storage().ref('/ProfilePictures/MyUserNewPicture.png').getDownloadURL().then((pic) =>{ 
    // do your stuff 
})