[英]Firebase not returning downloadURL in metaData with typescript and Ionic3
我已經努力工作了好幾天才能讓Firebase返回元數據中的downloadURL。 所有帳戶都應在其中,因為元數據包括fullPath和其他信息,但不包括downloadURL。
addItem(
itemName: string,
eventId: string,
itemPicture: string = null
): PromiseLike<any> {
return this.activityListRef
.child(`${eventId}/itemList`)
.push({ itemName })
.then(newItem => {
this.activityListRef.child(eventId).transaction(event => {
return event;
});
if (itemPicture != null) {
return firebase
.storage()
.ref(`/item/${newItem.key}/profilePicture.png`)
.putString(itemPicture, 'base64', { contentType: 'image/png' })
.then(savedPicture => {
console.log(savedPicture.metadata);
this.activityListRef
.child(`${eventId}/itemList/${newItem.key}/profilePicture`)
.set(savedPicture.downloadURL);
});
}
});
}
如果我在控制台中登錄,則可以看到除downloadURL以外的所有內容
我也嘗試更改.set(savedPicture.downloadURL); 設置為.set(savedPicture.metadata.downloadURLS [0]);
但在任何響應參數中仍然沒有downloadURL項。
有任何想法嗎?
使用putString方法上傳原始字符串后,請使用相同的ref並使用getDownloadUrl()方法獲取如下所示的網址,
storage()
.ref(`/item/${newItem.key}/profilePicture.png`).getDownloadUrl() // which returns promise in turn returns the image url once it's available.
就您而言,您可以像下面這樣
var storageRef = firebase.storage().ref(`/item/${newItem.key}/profilePicture.png`)
return storageRef.putString(itemPicture, 'base64', { contentType: 'image/png' })
.then(savedPicture => {
storageRef.getDownloadUrl()
.then(url =>{
this.activityListRef
.child(`${eventId}/itemList/${newItem.key}/profilePicture`)
.set(url);
});
});
希望這可以幫助
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.