我正在使用 ionic 5 和 angular 9 將資料 url 上傳到 firebase 存盤。我的代碼運行良好,但我不確定如何等到下載 url 可用。
下面是代碼
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
我像這樣在我的相機插件中呼叫它
this.uploadToFireStore(base64Image)
console.log("updated with url:", this.downloadURL)
目前下載網址稍后列印,我的代碼沒有等待下載網址出現。我需要這個 url 上傳到我的 RTDB,所以請告訴我如何在不將代碼移動到這部分的情況下做到這一點
getDownloadURL(snapshot.ref).then((downloadURL) => {
...
uj5u.com熱心網友回復:
您可能只需要回傳您的承諾鏈:
uploadToFireStore(imageData){
const storage = getStorage();
const storageRef = ref(storage, (new Date().getTime().toString()));
return uploadString(storageRef, imageData, 'data_url').then((snapshot) => {
return getDownloadURL(snapshot.ref).then((downloadURL) => {
console.log('File available at', downloadURL);
this.downloadURL = downloadURL
});
});
}
然后你可以這樣做:
this.uploadToFireStore(base64Image).then(() => {
console.log("updated with url:", this.downloadURL)
});
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/424047.html
標籤:javascript 有角度的 火力基地 离子框架 firebase-存储
上一篇:桌面上沒有側邊選單的離子列印
下一篇:使用后退按鈕后結果陣列仍然存在
